Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import collections
- import multiprocessing
- import os
- import time
- from pprint import pprint
- Student = collections.namedtuple('Student', [
- 'name',
- 'born',
- 'gender',
- 'location',
- ])
- students = (
- Student(name='Valentyn Marusyk', born=1998, gender='male', location='Chernivtsi'),
- Student(name='Debora Jheryada', born=1999, gender='female', location='Chernivtsi'),
- Student(name='Vitaliy Kapaniyk', born=1998, gender='male', location='Ivano-Frankivsk'),
- Student(name='Sanya Tatarchyk', born=1996, gender='male', location='Chernivtsi'),
- Student(name='Sanya Pankevich', born=1998, gender='male', location='Chernivtsi'),
- Student(name='Denis Malaiko', born=1998, gender='male', location='Chernivtsi'),
- )
- pprint(students)
- print()
- def transform(x):
- print(f'Process {os.getpid()} working record {x.name}')
- time.sleep(1)
- result = {'name': x.name, 'age': 2019 - x.born}
- print(f'Process {os.getpid()} done processing record {x.name}')
- return result
- start = time.time()
- pool = multiprocessing.Pool()
- result = pool.map(transform, students)
- #result = tuple(map(transform, students))
- end = time.time()
- print(f'\n Time to complete: {end - start:.2f}s\n')
- pprint(result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement