【发布时间】:2021-03-16 00:05:37
【问题描述】:
我想在我的 liunx 操作系统上运行多个命令,所以我创建了一个脚本来运行多个命令,但有些命令执行时间过长,但我想终止执行时间超过 1 分钟的命令。 我该怎么做?
import subprocess
import threading
import time
from time import sleep
def prog(line):
def worker(line):
print(line)
subprocess.call(line, shell=True )
t = threading.Thread(target=worker, args=(line,))
t.start()
f=open("a",'r')
for line in f:
prog(line)
【问题讨论】:
标签: python python-3.x multithreading subprocess python-multithreading