您的位置:首页 > 编程语言 > Python开发

python中subprocess.Popen.poll

2016-04-10 20:05 387 查看
import subprocess

proc = subprocess.Popen(['python', 'test.py'], stdout=subprocess.PIPE)

while 1:
print proc.poll()


#while 1:
#     print "hello"

print "hello"


测试代码如上,poll函数返回码:

0 正常结束

1 sleep

2 子进程不存在

-15 kill

None 在运行

poll的返回: A None value indicates that the process hasn’t terminated yet.A negative value -N indicates that the child was terminated by signal N (Unix only).

ps:=====================================================================================================

self.proc.poll() == 0 判断子进程是否正常结束 正确
self.proc.poll() <= 0 会导致进程在一段时间内没有上报状态 具体原因??? 有问题



self.proc.poll() is not None判断进行是否结束
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: