在超时使用模块“子进程”
下面是运行返回它的任意命令的Python代码stdout数据,或对非零退出代码引发异常:
stdout
proc = subprocess.Popen( cmd, stderr=subprocess.STDOUT, # Merge stdout and stderr stdout=subprocess.PIPE, shell=True)
communicate用于等待进程退出:
communicate
stdoutdata, stderrdata = proc.communicate()
这个subprocess因此,模块不支持超时-停止运行超过X秒的进程的能力-因此,communicate可能要花很长时间才能跑。
subprocess
什么是最简单在运行在Windows和Linux上的Python程序中实现超时的方法?
慕尼黑的夜晚无繁华
ITMISS
相关分类