酸洗错误:无法酸洗< type'function'> [英] Pickling error: Can't pickle <type 'function'>
问题描述
我想知道这个错误可能意味着什么:
I am wondering what this error might mean:
PicklingError: Can't pickle <type 'function'>: attribute lookup __builtin__.function failed
我知道这与使用多个内核有关.我正在群集上运行程序,并在代码的这一行中使用了15个线程:
I understand that it has something to do with using multiple cores. I am running my program on a cluster and using 15 threads in this line of my code:
gauss2 = PTSampler(ntemps, renwalkers, rendim, lnlike, lnprior, threads=15)
有问题的采样器是在 http://dan.iel.fm/emcee/current/user/pt/
知道这个错误可能意味着什么吗?
Any idea what this error might mean?
推荐答案
该错误表示您正在尝试对内置的FunctionType
进行腌制,而不是对函数本身进行腌制.可能是在某处拾取了函数的类而不是函数本身的地方出现了编码错误.
The error means you are trying to pickle a builtin FunctionType
… not the function itself. It's likely do to a coding error somewhere picking up the class of the function instead of the function itself.
>>> import sys
>>> import pickle
>>> import types
>>> types.FunctionType
<type 'function'>
>>> try:
... pickle.dumps(types.FunctionType)
... except:
... print sys.exc_info()[1]
...
Can't pickle <type 'function'>: it's not found as __builtin__.function
>>> def foo(x):
... return x
...
>>> try:
... pickle.dumps(type(foo))
... except:
... print sys.exc_info()[1]
...
Can't pickle <type 'function'>: it's not found as __builtin__.function
>>> try:
... pickle.dumps(foo.__class__)
... except:
... print sys.exc_info()[1]
...
Can't pickle <type 'function'>: it's not found as __builtin__.function
>>> pickle.dumps(foo)
'c__main__\nfoo\np0\n.'
>>> pickle.dumps(foo, -1)
'\x80\x02c__main__\nfoo\nq\x00.'
如果有一个FunctionType
对象,那么您所要做的就是获取该类的实例之一-即像foo
这样的函数.
If you have a FunctionType
object, then all you need to do is get one of the instances of that class -- i.e. a function like foo
.
这篇关于酸洗错误:无法酸洗< type'function'>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!