这是运行任意命令以返回其stdout数据或在非零退出代码上引发异常的Python代码:
proc = subprocess.Popen(
cmd,
stderr=subprocess.STDOUT, # Merge stdout and stderr
stdout=subprocess.PIPE,
shell=True)
Run Code Online (Sandbox Code Playgroud)
子进程模块不支持执行时间,并且如果它超过特定阈值=>超时(杀死运行时间超过X秒的进程的能力)
在打算在Linux上运行的Python2.6程序中,实现get_execution_time和timeout的最简单方法是什么?
multithreading subprocess timeout python-2.x python-multithreading