You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12 lines
343 B
Python

# Пул потоков, concurrent.futures.Future
from concurrent.futures import ThreadPoolExecutor, as_completed
def f(a):
return a * a
# .shutdown() in exit
with ThreadPoolExecutor(max_workers=3) as pool:
results = [pool.submit(f, i) for i in range(10)]
for future in as_completed(results):
print(future.result())