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
但是有时候加上了这句,有时候会报错 OSError: [Errno 12] Cannot allocate memory,
import gc
gc.collect()
主动回收内存
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()
主动回收内存
相关文章推荐
- 深入分析 iBATIS 框架之系统架构与映射原理
- 详解Linux环境下使Nginx服务器支持中文url的配置流程
- some command of executing hadoop spark hive kafka
- Linux hostname --显示或设置主机名
- Linux help --显示Bash内建命令的帮助信息
- Linux head --显示档案的开头
- 【首度披露】乐视电商云的整体架构与技术实现
- Linux halt --停止系统运行,但不关闭电源
- Linux hadoop --分布式文件系统
- Linux gzip --文件解压缩
- 自动化运维的基石:CMDB
- opencv读取图片,视频文件,摄像头
- 给 Linux 系统“减肥”,系统垃圾清理
- Linux groupmod --修改用户组
- Linux groupdel --删除群组
- CentOS 6使用rpm方式安装JDK8
- Linux groupadd --添加用户组
- Linux grep --搜索工具
- Linux gpg --加密和数字签名工具
- Linux getopts --处理命令行参数,并校验有效选项