设为首页 加入收藏

TOP

Python使用subprocess.Popen导致子进程hang住
2014-11-24 08:24:46 来源: 作者: 【 】 浏览:0
Tags:Python 使用 subprocess.Popen 导致 进程 hang

subprocess用于在python内部创建一个子进程,比如调用shell脚本等。


举例:


p = subprocess.Popen(cmd, stdout = subprocess.PIPE, stdin = subprocess.PIPE, shell = True)
p.wait()
// hang here
print "subprocess finished"


在python的官方文档中对这个进行了解释:http://docs.python.org/2/library/subprocess.html


原因是stdout产生的内容太多,超过了系统的buffer


解决方法是使用communicate()方法。


p = subprocess.Popen(cmd, stdout = subprocess.PIPE, stdin = subprocess.PIPE, shell = True)
stdout, stderr = p.communicate()
p.wait()
print "subprocess finished"


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C语言获取开机时间(结合VBS脚本实.. 下一篇为什么log4j的概念模型是错的--zl..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·微服务 Spring Boot (2025-12-26 18:20:10)
·如何调整 Redis 内存 (2025-12-26 18:20:07)
·MySQL 数据类型:从 (2025-12-26 18:20:03)
·Linux Shell脚本教程 (2025-12-26 17:51:10)
·Qt教程,Qt5编程入门 (2025-12-26 17:51:07)