Guest User

Untitled

a guest
May 23rd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. import multiprocessing
  2. import functools
  3.  
  4. def compose(*functions):
  5. return functools.reduce(lambda f, g: lambda x: f(g(x)), functions, lambda x: x
  6.  
  7. twox = lambda x: 2*x
  8. operation = compose(*funcs)
  9. nums = range(10)
  10.  
  11. p = multiprocessing.Pool(processes=3)
  12. p.map(operation, nums) ## raises an AttributeError
  13.  
  14. def wrapped_operation(x):
  15. return operation(x)
  16.  
  17. p = multiprocessing.Pool(processes=3)
  18. p.map(wrapped_operation, nums) ## returns [0,8,16,...]
Add Comment
Please, Sign In to add comment