[IPython-user] Enhancements to ipython1: pushing/pulling functions

Brian Granger ellisonbg.net@gmail....
Thu Oct 4 16:21:20 CDT 2007


I have just checked in some changes to ipython1 that make it possible
to push and pull functions to and from engines:

In [1]: import ipython1.kernel.api as kernel
In [2]: rc = kernel.RemoteController(('',10105))
In [3]: def f(x): return 2.0*x

In [4]: rc.pushAll(f=f)                            # push the actual function!
Out[4]: [None, None, None, None]

In [5]: rc.executeAll('y=f(10)')             # now call the function
In [6]: rc.pullAll('y')
Out[6]: [20.0, 20.0, 20.0, 20.0]

We have also adapted the rc.map/mapAll and parallelize methods to take
functions as well:

In [7]: rc.mapAll(lambda x: x*x, range(16))
Out[7]: [0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225]

Please try these new features out and let us know how they work.

Some limitations:

1.  Only functions and lambdas can be pushed and pulled.   Instances
of classes that are callables don't work unless the class is already
defined on the engines.
2.  Functions with closures don't work.
3.  Functions that reference global variables work fine though.

Over the coming weeks, we will begin to incorporate these new features
into other parts of ipython1, such as the TaskController.



More information about the IPython-user mailing list