Skip to content

Instantly share code, notes, and snippets.

@kaanberke
Last active February 11, 2020 09:28
Show Gist options
  • Select an option

  • Save kaanberke/dae39c9fdf3f1c21f6f1b37d3a02623f to your computer and use it in GitHub Desktop.

Select an option

Save kaanberke/dae39c9fdf3f1c21f6f1b37d3a02623f to your computer and use it in GitHub Desktop.
Process Pool Executor
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