#!/usr/bin/env python # coding: utf-8 # In[14]: def _recv_module(name, code): """Given a module name and code as text create an imported module in-memory. """ import sys, types sys.modules[name] = mod = types.ModuleType(name) exec(code, mod.__dict__) def send_module(view, name, path): """send a local module to the engines, without writing any files.""" with open(path) as f: code = f.read() return view.apply(_recv_module, name, code) # In[5]: get_ipython().run_cell_magic('writefile', 'mymodule.py', '\nconstant = 5\ndef foo(x):\n return constant * x\n\ndef bar(y):\n return foo(y)\n') # In[8]: import ipyparallel as ipp rc = ipp.Client() engines = rc[:] view = rc.load_balanced_view() # In[9]: import mymodule # In[10]: view.apply_sync(mymodule.bar, 5) # In[15]: send_module(engines, 'mymodule', 'mymodule.py').get() # In[17]: view.apply_sync(mymodule.bar, 10)