【发布时间】:2012-09-11 15:55:58
【问题描述】:
可能重复:
subprocess with timeout
Best way to launch a process and block until it is finished
我有一个 python 代码,我需要在其中运行像“curl --user ....”这样的 Linux 命令。我需要运行这个命令 3600 秒。 3600 秒后,我需要终止“Linux 命令进程”。我怎么可能做到这一点?
def timeout_command(command, timeout):
import os, datetime, time, signal
start = datetime.datetime.now()
time_pass = 0
while (time_pass < timeout):
process = os.system(command)
now = datetime.datetime.now()
time_pass = (now-start).seconds
print time_pass
print timeout_command("curl --user...", 3600)
print "Other2"
print "Other3"
关于如何杀死它的任何线索:“process = os.system(command)”?
最好的问候,
【问题讨论】: