def make_closure(a): """make a function with a closure, and return it""" def has_closure(b): return a * b return has_closure closer = make_closure(5) closer(2) import pickle pickle.dumps(closer) import dill pickle.dumps(closer)[:64] + '...' from IPython import parallel rc = parallel.Client() view = rc.load_balanced_view() from types import FunctionType from IPython.utils.pickleutil import can_map can_map.pop(FunctionType, None) from IPython.kernel.zmq import serialize serialize.pickle = pickle view.apply_sync(closer, 3) view.apply_sync(make_closure, 2) %%px --local # load dill import dill # disable special function handling from types import FunctionType from IPython.utils.pickleutil import can_map can_map.pop(FunctionType, None) # fallback to pickle instead of cPickle, so that dill can take over import pickle from IPython.kernel.zmq import serialize serialize.pickle = pickle remote_closure = view.apply_sync(make_closure, 4) remote_closure(5) def outer(a): def inner(b): def inner_again(c): return c * b * a return inner_again return inner view.apply_sync(lambda f: f(3),view.apply_sync(outer, 1)(2))