Created
September 6, 2012 21:55
-
-
Save saghul/3660656 to your computer and use it in GitHub Desktop.
Python concurrent.futures example
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, 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