Created
December 24, 2017 16:58
-
-
Save Day0Dreamer/4fe8939b95c214c7c2178c2c838f34e3 to your computer and use it in GitHub Desktop.
https://dbader.org/blog/python-parallel-computing-in-60-seconds
https://www.youtube.com/watch?v=aysceqdGFw8&list=PLP8GkvaIxJP1z5bu4NX_bFrEInBkAgTMr&index=5
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
""" | |
Python Parallel Processing (in 60 seconds or less) | |
https://dbader.org/blog/python-parallel-computing-in-60-seconds | |
""" | |
import collections | |
import multiprocessing | |
Scientist = collections.namedtuple('Scientist', [ | |
'name', | |
'born', | |
]) | |
scientists = ( | |
Scientist(name='Ada Lovelace', born=1815), | |
Scientist(name='Emmy Noether', born=1882), | |
Scientist(name='Marie Curie', born=1867), | |
Scientist(name='Tu Youyou', born=1930), | |
Scientist(name='Ada Yonath', born=1939), | |
Scientist(name='Vera Rubin', born=1928), | |
Scientist(name='Sally Ride', born=1951), | |
) | |
def process_item(item): | |
return { | |
'name': item.name, | |
'age': 2017 - item.born | |
} | |
if __name__ == '__main__': | |
pool = multiprocessing.Pool() | |
result = pool.map(process_item, scientists) | |
print(tuple(result)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment