有人能让我了解这个错误是什么,出了什么问题以及如何解决它吗。我对python和学习还很陌生,想在代码中实现一些多处理,所以从它的基本方法开始
> AttributeError: Can't pickle local object
> 'computation.abc.<locals>.s1'
> Traceback (most recent call last):
> File "<string>", line 1, in <module>
> File "C:Pythonlibmultiprocessingspawn.py", line 116, in spawn_main
> exitcode = _main(fd, parent_sentinel)
> File "C:Pythonlibmultiprocessingspawn.py", line 126, in _main
> self = reduction.pickle.load(from_parent)
> EOFError: Ran out of input
我的代码如下:
import multiprocessing
class computation:
def abc(self):
try:
"""Some
logic
here"""
except Exception as E:
print('Error : ', E)
def func1(sfunc1):
"""some
logic
here"""
def func2(sfunc2):
"""some
logic
here"""
def check(stk):
p1 = multiprocessing.Process(target=func1, args=s1) # s1 and s2 is a List
p2 = multiprocessing.Process(target=func2, args=s2)
p1.start()
p2.start()
p1.join()
p2.join()
check(Symbols)
多处理器使用pickle在子进程之间串行化和传输数据。
Pickle无法序列化本地(内部(函数。尝试将target
设置为从文件的命名空间可见的函数。
例如:
import multiprocessing
def abc(self):
try:
"""Some
logic
here"""
except Exception as E:
print('Error : ', E)
def func1(sfunc1):
"""some
logic
here"""
def func2(sfunc2):
"""some
logic
here"""
def check(stk):
p1 = multiprocessing.Process(target=func1, args=s1) # s1 and s2 is a List
p2 = multiprocessing.Process(target=func2, args=s2)
p1.start()
p2.start()
p1.join()
p2.join()
if __name__ == "__main__": # Make sure only 1 process runs this.
check(Symbols)
确保定义了s1
、s2
和Symbols
。