# __author: "ZXYang"
# date: 2020/12/23
"""
max_workers:最多执行任务数(cpu核数 x 5 )
submit:线程池中提交任务
"""
import time
from concurrent.futures.thread import ThreadPoolExecutor
def work1():
print("==========work1==========")
for i in range(6):
time.sleep(0.5)
print(f‘work1:第{i+1}秒‘)
def work2():
print("===========work2=========")
for i in range(6):
time.sleep(0.5)
print(f‘work2:第{i+1}秒‘)
with ThreadPoolExecutor(max_workers=6 * 5) as f:
f.submit(work1)
f.submit(work2)
原文:https://www.cnblogs.com/zxy01/p/14181689.html