Last active
November 18, 2019 07:50
-
-
Save Ken-Kuroki/4f8f567f0800f890e5f8a5550b1ec991 to your computer and use it in GitHub Desktop.
Python process pooling
This file contains 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 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))} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For
imap
,imap_unordered
, andmap_async
, refer to https://stackoverflow.com/questions/26520781/multiprocessing-pool-whats-the-difference-between-map-async-and-imap