python 子进程超时退出

一:循环 忙等 子进程结束

import subprocess  
import os  
import time  
tt = '555'  
cmd = "python /home/100003/python/mypython/sub2.py "+" 333"+" 444 "+tt  
print time.time()  
sub2 = subprocess.Popen(cmd, shell=True)  
while 1:  
    ret1 = subprocess.Popen.poll(sub2)  
    if ret1 == 0:  
        print sub2.pid,'end'  
        break  
    elif ret1 is None:  
        print  'running'  
        time.sleep(1)  
    else:  
        print sub2.pid,'term'  
        break  
print time.time()  

 

posted @ 2014-09-05 09:18  taotaowill  阅读(3174)  评论(0编辑  收藏  举报