python_examples/thread_pool_patterns/submit_use_sequentially.py

23 lines
476 B
Python
Executable File

#!/usr/bin/env python3
from time import sleep
from random import randint
from concurrent.futures import ThreadPoolExecutor
def add_one(number):
print(number)
sleep(randint(0, 2))
return number + 1
def main():
with ThreadPoolExecutor(32) as executor:
futures = [executor.submit(add_one, number) for number in range(10)]
print(futures)
for future in futures:
print(future.result())
if __name__ == "__main__":
main()