import multiprocessing
import time
def random_stuff_to_do():
time.sleep(1)
print("Slept 1 second")
task1 = multiprocessing.Process(target = random_stuff_to_do)
task2 = multiprocessing.Process(target = random_stuff_to_do)
task1.start()
task2.start()
task1.join() #This part is usefull only if you want to wait for your tasks to end
task2.join() #before the program to continue.
print("Task 1 and 2 done at the same time")
您需要使用this答案中所示的线程
pip安装多处理
相关问题 更多 >
编程相关推荐