Skip to content

Instantly share code, notes, and snippets.

@natl
Created March 17, 2016 11:20
Show Gist options
  • Select an option

  • Save natl/6fafd842f93f454c616b to your computer and use it in GitHub Desktop.

Select an option

Save natl/6fafd842f93f454c616b to your computer and use it in GitHub Desktop.
Small multiprocessing example
from multiprocessing import Queue, Pool
def run_job(val):
x = 0
for ii in range(val):
x += ii**2
return x
if __name__ == "__main__":
tasks = [ii for ii in range(100000)]
result_queue = Queue()
pool = Pool(processes=2)
results = [pool.apply_async(run_job, (task,)) for task in tasks]
r = [result.get() for result in results]
print "Results: " + str(sum(r))
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment