Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. In [1]: from distributed import Executor
  2.  
  3. In [2]: e = Executor('127.0.0.1:8786')
  4.  
  5. In [3]: e
  6. Out[3]: <Executor: scheduler="127.0.0.1:8786" processes=2 cores=2>
  7.  
  8. In [4]: import socket
  9.  
  10. In [5]: e.run(socket.gethostname)
  11. Out[5]: {'172.20.12.7:53405': 'n1015', '172.20.12.8:53779': 'n1016'}
  12.  
  13. In [6]: %%file mod.py
  14. ...: def hostname():
  15. ...: return 'the hostname'
  16. ...:
  17. Overwriting mod.py
  18.  
  19. In [7]: import mod
  20.  
  21. In [8]: mod.hostname()
  22. Out[8]: 'the hostname'
  23.  
  24. In [9]: e.run(mod.hostname)
  25. distributed.utils - ERROR - No module named 'mod'
  26.  
  27. e.upload_file('mod.py')
  28.  
  29. In [1]: from math import sin
  30.  
  31. In [2]: import pickle
  32.  
  33. In [3]: pickle.dumps(sin)
  34. Out[3]: b'x80x03cmathnsinnqx00.'
  35.  
  36. In [3]: import mod
  37.  
  38. In [4]: import new
  39.  
  40. In [5]: def remote(func):
  41. ...: return new.function(func.func_code, func.func_globals, closure=func.func_closure)
  42. ...:
  43.  
  44. In [6]: e.run(remote(mod.hostname))
  45. Out[6]: {'tcp://10.0.2.15:44208': 'the hostname'}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement