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判断进行是否结束

 

posted on 2016-04-10 20:05  妞溜溜  阅读(12960)  评论(0编辑  收藏  举报