0

I am unable to send object to direct view workers. Here is what I want to do:

class Test:
  def __init__(self):
    self.id = 'ddfdf'

from IPython.parallel import Client
rc = Client()
dv = rc[:]
t = Test()
dv['t'] = t
print dv['t']

NameError: name 't' is not defined

This would work if I try to push pandas object or any of the build in objects. What is the way to do it with custom object?

I tried:

dv['Test'] = Test
dv['t'] = t
print dv['t']
UnpicklingError: NEWOBJ class argument isn't a type object

Ivelin
  • 12,293
  • 5
  • 37
  • 35

1 Answers1

2

For interactively defined classes (in __main__), you do need to push the class definition, or use dill. But even this doesn't appear to work for old-style classes, which is a bug in IPython's handling of old-style classes[1]. This code works fine if you use a new-style class:

class Test(object):
    ...

instead of on old-style class. Note that old-style classes are not available in Python 3. It's generally a good idea to always use new-style classes anyway.

minrk
  • 37,545
  • 9
  • 92
  • 87
  • minrk: Your suggestion works for the example but when I import the Test class from file: 'from test import Test' then dv['Test'] = Test will fail. Do you have any suggestions? – Ivelin Jun 20 '14 at 02:25
  • You shouldn't need to push Test if it's in a module, but the module itself does need to be available. Is the module a local file? If so, it's probably a good idea to send the file to all of your machines. If your engines are local, then you may just want to make sure the engines have the same CWD as the Client. – minrk Jun 25 '14 at 19:19