Last active
February 11, 2020 09:28
-
-
Save kaanberke/dae39c9fdf3f1c21f6f1b37d3a02623f to your computer and use it in GitHub Desktop.
Process Pool Executor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from concurrent.futures import ProcessPoolExecutor, as_completed | |
| from time import sleep | |
| from random import randint | |
| def take_sometime(number): | |
| sleep(randint(1, 5)) | |
| return f'Return of {number}' | |
| executor = ProcessPoolExecutor(max_workers=5) | |
| futures = [] | |
| for i in range(5): | |
| futures.append(executor.submit(take_sometime, i)) | |
| for i in as_completed(futures): | |
| print(i.result()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment