Skip to content

Instantly share code, notes, and snippets.

@thomo
Created June 17, 2019 08:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomo/53c0c1db5938a80b5fe68631cfa99633 to your computer and use it in GitHub Desktop.
Save thomo/53c0c1db5938a80b5fe68631cfa99633 to your computer and use it in GitHub Desktop.
import collections
import multiprocessing
import time
startzeit = time.time()
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 { # same line
'name': item.name,
'age': 2017 - item.born
}
if __name__ == '__main__': # only in main
pool = multiprocessing.Pool() # number of worker processes depends on CPU
result = pool.map(process_item, scientists)
print(tuple(result))
endzeit = time.time()
diff = endzeit - startzeit
print("Zeit:" + str(diff))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment