2016-11-30 27 views
1

Ipyparallel错误运行此代码,我有这样的错误:与DIRECTVIEW

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) 

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

回答

0

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修饰符,但这完全是另一个问题,我建议您通过文档中的示例来熟悉它们)