def long_time_task(i):
print('当前子线程: {} - 任务{}'.format(threading.current_thread().name, i))
time.sleep(5)
print("结果: {}".format(8 ** 20))
start = time.time()
print('这是主线程:{}'.format(threading.current_thread().name))
t1 = threading.Thread(target=long_time_task, args=(1,))
t2 = threading.Thread(target=long_time_task, args=(2,))
t1.start()
t2.start()
t1.join()
t2.join()
end = time.time()
print("总共用时{}秒".format((end - start)))
这是主线程:MainThread
当前子线程: Thread-1 - 任务1
当前子线程: Thread-2 - 任务2
结果: 1152921504606846976
结果: 1152921504606846976
总共用时5.000285863876343秒