import subprocess
# I want these to happen simultaneously:
subprocess.call(scriptA + argumentsA)
subprocess.call(scriptA + argumentsB)
subprocess.call(scriptA + argumentsC)
# I want to wait until the above threads are all finished, and then run this:
print("All threads are done.")
我尝试使用像这个例子这里所示的
threading
。from threading import Thread
import subprocess
def call_script(args)
subprocess.call(args)
t1 = Thread(target=call_script, args=(scriptA + argumentsA))
t2 = Thread(target=call_script, args=(scriptA + argumentsB))
t3 = Thread(target=call_script, args=(scriptA + argumentsC))
t1.start()
t2.start()
t3.start()
# TODO: Wait for all threads to finish.
print("All threads are done.")
如何在运行最后一行代码之前等待线程完成?
for x in threads: x.join()
而不是列表推导式。 - Ioan Alexandru Cucu