daily pastebin goal
68%
SHARE
TWEET

Untitled

a guest Mar 25th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import collections
  2. import multiprocessing
  3. import os
  4. import time
  5. from pprint import pprint
  6.  
  7. Student = collections.namedtuple('Student', [
  8.     'name',
  9.     'born',
  10.     'gender',
  11.     'location',
  12. ])
  13.  
  14. students = (
  15.     Student(name='Valentyn Marusyk', born=1998, gender='male', location='Chernivtsi'),
  16.     Student(name='Debora Jheryada', born=1999, gender='female', location='Chernivtsi'),
  17.     Student(name='Vitaliy Kapaniyk', born=1998, gender='male', location='Ivano-Frankivsk'),
  18.     Student(name='Sanya Tatarchyk', born=1996, gender='male', location='Chernivtsi'),
  19.     Student(name='Sanya Pankevich', born=1998, gender='male', location='Chernivtsi'),
  20.     Student(name='Denis Malaiko', born=1998, gender='male', location='Chernivtsi'),
  21. )
  22. pprint(students)
  23. print()
  24.  
  25.  
  26. def transform(x):
  27.     print(f'Process {os.getpid()} working record {x.name}')
  28.     time.sleep(1)
  29.     result = {'name': x.name, 'age': 2019 - x.born}
  30.     print(f'Process {os.getpid()} done processing record {x.name}')
  31.     return result
  32.  
  33.  
  34. start = time.time()
  35.  
  36. pool = multiprocessing.Pool()
  37. result = pool.map(transform, students)
  38. #result = tuple(map(transform, students))
  39.  
  40. end = time.time()
  41.  
  42. print(f'\n Time to complete: {end - start:.2f}s\n')
  43. pprint(result)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top