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

2
  • Knowing something about how pickle works, try pushing the class (Test) before the instance (t). Commented Jun 20, 2014 at 0:31
  • Is there a way to do this with out pushing the class first? Commented Jun 20, 2014 at 0:38

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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?
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.