[IPython-dev] pushing python class definition to engines

Andrew Straw strawman at astraw.com
Tue Jul 15 20:01:03 EDT 2008


After seeing Brian Granger's great demo of the parallel abilities in
IPython last week at the SIAM conference, I'm playing with ipython trunk
which I just pulled out of launchpad (for this reason, I'm posting on
the -dev list).

Anyhow, if I start a client in the usual way:

from IPython.kernel import client
mec = client.MultiEngineClient()

I can easily push Python integers:

a=5
mec['a'] = a
print mec.gather('a')

But pushing classes doesn't work:

class MyObj(object):
    def __init__(self,x):
        print 'PID',os.getpid()
        self.x=x

mec['MyObj'] = MyObj
print mec.gather('MyObj')

That gives the following error. How can I push a class definition to my
engines?

Traceback (most recent call last):
  File "flydra/test_ipython.py", line 14, in <module>
    mec.push_function(dict(MyObj= MyObj,))
  File
"/home/astraw/PY_ipython/lib/python2.5/site-packages/IPython/kernel/multiengineclient.py",
line 606, in push_function
    return self._blockFromThread(self.smultiengine.push_function,
namespace, targets=targets, block=block)
  File
"/home/astraw/PY_ipython/lib/python2.5/site-packages/IPython/kernel/multiengineclient.py",
line 456, in _blockFromThread
    result = blockingCallFromThread(function, *args, **kwargs)
  File
"/home/astraw/PY_ipython/lib/python2.5/site-packages/IPython/kernel/twistedutil.py",
line 69, in blockingCallFromThread
    return twisted.internet.threads.blockingCallFromThread(reactor, f,
*a, **kw)
  File
"/home/astraw/PY_ipython/lib/python2.5/site-packages/Twisted-8.1.0-py2.5-linux-x86_64.egg/twisted/internet/threads.py",
line 83, in blockingCallFromThread
    result.raiseException()
  File
"/home/astraw/PY_ipython/lib/python2.5/site-packages/Twisted-8.1.0-py2.5-linux-x86_64.egg/twisted/python/failure.py",
line 319, in raiseException
    raise self.type, self.value, self.tb
AttributeError: 'module' object has no attribute 'MyObj'




More information about the IPython-dev mailing list