酸洗错误:不能酸洗<type 'function'>

Pickling error: Can#39;t pickle lt;type #39;function#39;gt;(酸洗错误:不能酸洗lt;type functiongt;)
本文介绍了酸洗错误:不能酸洗<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__
foo
p0
.'
>>> pickle.dumps(foo, -1)
'x80x02c__main__
foo
qx00.'

如果您有一个 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.

这篇关于酸洗错误:不能酸洗&lt;type 'function'&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Multiprocessing on Windows breaks(Windows 上的多处理中断)
How to use a generator as an iterable with Multiprocessing map function(如何将生成器用作具有多处理映射功能的可迭代对象)
read multiple files using multiprocessing(使用多处理读取多个文件)
Why does importing module in #39;__main__#39; not allow multiprocessig to use module?(为什么在__main__中导入模块不允许multiprocessig使用模块?)
Trouble using a lock with multiprocessing.Pool: pickling error(使用带有 multiprocessing.Pool 的锁时遇到问题:酸洗错误)
Python sharing a dictionary between parallel processes(Python 在并行进程之间共享字典)