【发布时间】:2021-05-01 16:57:07
【问题描述】:
我在python 中编写脚本。
我需要写入磁盘,并运行一些 shell 脚本。
但是,根据输入的不同,这些可能需要很长时间,如果它们花费的时间太长,我想杀死它们。
我想要类似的东西:
def run_once(input_text):
with open("temp.file", "w") as f:
f.write(input_text)
os.system("./synthesize.sh temp.tsl")
for single in many:
if(takes_more_than_60_seconds(run_once(input_text)):
kill(process)
print("Process killed since it took too long. Moving to the next job.")
【问题讨论】:
-
这个帖子有一个很好的例子:stackoverflow.com/questions/2281850/…