您的位置:首页 > 运维架构

subprocess.Popen() close_fds问题 OSError: [Errno 12] Cannot allocate memory

2016-04-08 10:16 579 查看
使用subprocess.Popen() 来调用命令时竟然发现response确实是返回到客户端了,但是服务器端和客户端的http连接竟然还连接着,一直不断。

python的文档,发现:http://docs.python.org/library/subprocess.html

cmd = 'ps aux | grep "memcached .* %s"' % port
p = subprocess.Popen(cmd, shell=True, close_fds=True, # 必须加上close_fds=True,否则子进程会一直存在
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
需要加上 close_fds=True, # 必须加上close_fds=True,否则子进程会一直存在
但是有时候加上了这句,有时候会报错 OSError: [Errno 12] Cannot allocate memory,
import gc

gc.collect()

主动回收内存
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: