【发布时间】:2021-09-02 22:49:42
【问题描述】:
Python ThreadPoolExecutor 没有并行运行,它正在依次调用cube方法,等待完成,
我需要运行 20 个并行线程
from concurrent.futures import ThreadPoolExecutor
from time import sleep
def cube(x):
sleep(2)
print(f'Cube of {x}:{x*x*x}')
count = 0
while True:
with ThreadPoolExecutor(max_workers=20) as exe:
exe.submit(cube,2)
count += 1
if count > 50:
break
【问题讨论】:
标签: python python-3.x multithreading threadpool python-multithreading