0
可能重複:
subprocess with timeout
Best way to launch a process and block until it is finishedPython - 如何在X秒後終止進程並繼續執行python代碼?
我有一個Python代碼,我需要像運行Linux命令 「捲曲--user ......」。我需要運行這個命令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)」?
最好的問候,