Skip to content

Instantly share code, notes, and snippets.

@saghul
Created September 6, 2012 21:55
Show Gist options
  • Save saghul/3660656 to your computer and use it in GitHub Desktop.
Save saghul/3660656 to your computer and use it in GitHub Desktop.
Python concurrent.futures example
from concurrent.futures import ProcessPoolExecutor, wait
from multiprocessing import cpu_count
try:
workers = cpu_count()
except NotImplementedError:
workers = 1
pool = ProcessPoolExecutor(max_workers=workers)
def hard_work():
# Do some CPU bond work here
pass
futures = [pool.submit(hard_work) for x in range(100)]
wait(futures)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment