简体   繁体   English

酸洗错误:不能泡菜<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

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: 我在一个集群上运行我的程序,并在我的代码行中使用15个线程:

gauss2 = PTSampler(ntemps, renwalkers, rendim, lnlike, lnprior, threads=15)

The sampler in question is the one documented for the Parallel Tempering sampler at http://dan.iel.fm/emcee/current/user/pt/ 有问题的采样器是在http://dan.iel.fm/emcee/current/user/pt/上为Parallel Tempering采样器记录的采样器。

Any idea what this error might mean? 知道这个错误可能意味着什么吗?

The error means you are trying to pickle a builtin FunctionType … not the function itself. 该错误意味着您正在尝试挑选内置的FunctionType ...而不是函数本身。 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.'

If you have a FunctionType object, then all you need to do is get one of the instances of that class -- ie a function like foo . 如果你有一个FunctionType对象,那么你需要做的就是获得该类的一个实例 - 即像foo这样的函数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 多处理:池和泡菜错误—泡菜错误:不能泡菜 <type 'instancemethod'> :属性查找__builtin __。instancemethod失败 - Multiprocessing: Pool and pickle Error — Pickling Error: Can't pickle <type 'instancemethod'>: attribute lookup __builtin__.instancemethod failed 多处理酸洗错误:_pickle.PicklingError:不能酸洗<function myProcess at 0x02B2D420> :它与 __main__.myProcess 不是同一个对象 - multiprocessing pickling error: _pickle.PicklingError: Can't pickle <function myProcess at 0x02B2D420>: it's not the same object as __main__.myProcess 酸洗Matplotlib情节提升PicklingError:不能腌制&#39;RendererAgg&#39;对象 - Pickling Matplotlib plot raising PicklingError: Can't pickle 'RendererAgg' object 不能腌制 Function - Can't pickle Function 尝试腌制对象实例会引发腌制错误 - Trying to pickle object instance throws pickling error PicklingError:不能泡菜 <type 'function'> 与python进程池执行程序 - PicklingError: Can't pickle <type 'function'> with python process pool executor Python 多处理酸洗错误:无法酸洗<type 'function'></type> - Python multiprocessing PicklingError: Can't pickle <type 'function'> 错误类型:无法腌制 _thread._local 对象 - error type :can't pickle _thread._local objects 什么是“类型错误:无法腌制弱引用对象” - What is "Type Error: can't pickle weakref objects" 当我尝试运行代码时,出现错误:PickingError:不能腌制 <type 'function'> :属性查找__builtin __。function失败 - when I try to run the code, it get the error:PicklingError: Can't pickle <type 'function'>: attribute lookup __builtin__.function failed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM