python线程池样例
from concurrent.futures import ThreadPoolExecutor
import time
def printperson(p):
print(p)
time.sleep(2)
person = ['anna','grey','all']
start = time.time()
# 抢占式线程池
with ThreadPoolExecutor(3) as executor:
for p in person:
executor.submit(printperson,p)
# 非抢占式线程池
# with ThreadPoolExecutor(3) as executor:
# executor.map(printperson,person)
end = time.time()
print(f'耗时:{end-start}')