Last active
February 5, 2020 10:02
-
-
Save 0atman/31d85fbad4e1cf68b218267c8b57d5ae to your computer and use it in GitHub Desktop.
A process-based pmap with sensible defaults, ready to go
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 pmap(f, collection, size=10): | |
""" | |
Applies `f` in parallel over `collection`. | |
Pool `size` has a sensible default of 10. | |
""" | |
with Pool(size) as p: | |
return p.map(f, collection) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And the Threaded version, useful on AWS Lamda, where processes are restricted: