【问题标题】:Ipyparallel error with directviewdirectview的Ipyparallel错误
【发布时间】:2016-11-30 05:11:12
【问题描述】:

运行此代码时,出现此错误:

from ipyparallel import error, AsyncHubResult, DirectView as dv, Reference

@dv.parallel(block=True)
def np_std_par(x):
    return np_std(x)

TypeError: unbound method parallel() must be called with 
DirectView instance as first argument (got nothing instead)

如何使用装饰器? 听起来不清楚。

【问题讨论】:

    标签: ipython ipython-parallel


    【解决方案1】:

    dv,如第一个代码块(及以上)所写,实际上不是DirectView

    from ipyparallel import DirectView as dv
    print(type(dv))
    <class 'traitlets.traitlets.MetaHasTraits'>
    

    DirectView 不需要导入,而是it should be created from a Client()

    import ipyparallel
    client = ipyparallel.Client()
    dv = client[:]
    
    print(type(dv))
    <class 'ipyparallel.client.view.DirectView'>
    

    现在装饰器将按预期执行。 (尽管看起来您可能必须在函数中导入 np_std 或使用 require 装饰器,但这完全是另一个问题,我建议您通过文档中的示例来熟悉)

    【讨论】:

      猜你喜欢
      • 2016-03-02
      • 1970-01-01
      • 2018-05-18
      • 2017-06-30
      • 2017-01-11
      • 2017-05-03
      • 2016-07-14
      • 2022-12-03
      • 2016-11-25
      相关资源
      最近更新 更多