【发布时间】:2012-05-30 19:49:55
【问题描述】:
我在网上搜索并学习了其他实现它的方法 现在我发现了这个问题。我的执行时间总是不止于此 如果我在 subprocess.Popen 中写入 stdout=subprocess.PIPE,则超时。如果我要删除它,那么它需要正常的执行时间
import subprocess, datetime, os, time, signal
//setting time for timeout
timeout=3
start = datetime.datetime.now()
process = subprocess.Popen(["python", "/home/bourne/untitled.py"],shell=False, stdout=subprocess.PIPE,stderr=subprocess.PIPE)
while process.poll() is None:
time.sleep(0.1)
now = datetime.datetime.now()
if (now - start).seconds > timeout:
os.kill(process.pid, signal.SIGKILL)
os.waitpid(-1, os.WNOHANG)
print "error"
print (now - start).seconds
break
print (now - start).seconds
【问题讨论】:
标签: python multithreading subprocess