ipython并行推送自定义对象 [英] ipython parallel push custom object

查看:105
本文介绍了ipython并行推送自定义对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法将对象发送给直接查看工作者。
这是我想做的事情:

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

如果我尝试推送pandas对象或任何构建对象,这将有效。
使用自定义对象的方法是什么?

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?

我试过:


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


推荐答案

用于交互式定义的类(在 __ main__中),您需要推送类定义,或使用 dill 。但即便如此,这似乎也不适用于旧式类,这是IPython处理旧式类的一个错误[1]。如果您使用新式类,此代码可以正常工作:

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):
    ...

而不是旧式的。请注意,旧式类在Python 3中不可用。
无论如何总是使用新式类通常是一个好主意。

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.

这篇关于ipython并行推送自定义对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆