Skip to content

Instantly share code, notes, and snippets.

@Ken-Kuroki
Last active November 18, 2019 07:50
Show Gist options
  • Save Ken-Kuroki/4f8f567f0800f890e5f8a5550b1ec991 to your computer and use it in GitHub Desktop.
Save Ken-Kuroki/4f8f567f0800f890e5f8a5550b1ec991 to your computer and use it in GitHub Desktop.
Python process pooling
from multiprocessing import Pool
def func(a): # in case you want to pass multiple arguments, pack them by making a data type, or use starmap
b = a**2
return a, b # return the argument in addition to the result for convenience
with Pool(20) as p:
output = {k: v for k, v in p.imap(func, range(100))}
@Ken-Kuroki
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment