我正在尝试将函数调用映射到池。我正在使用来自其他类似线程的修复程序,涉及使用多个参数调用函数。我不能包含一个更全面的例子,因为策略类的训练方法非常漫长而且复杂且数据集很大:
import multiprocessing as mp
from functools import partial
from numpy import array_split
def call_train(signals, args):
return args[0].train(signals, args[1])
pool = mp.Pool()
chunks = array_split(data.train_signals, pool._processes)
res = pool.map(partial(call_train, [strat, data.train_md]), chunks)
在上面,strat是一个python对象,data.train_signals和data.train_md都是pandas数据帧。
错误如下:
File "/home/jason/PycharmProjects/backtester/core/backtester.py", line 51, in evaluate
res = pool.map(partial(call_train, [strat, data.train_md]), chunks)
File "/usr/lib/python3.5/multiprocessing/pool.py", line 260, in map
return self._map_async(func, iterable, mapstar, chunksize).get()
File "/usr/lib/python3.5/multiprocessing/pool.py", line 608, in get
raise self._value
File "/usr/lib/python3.5/multiprocessing/pool.py", line 385, in _handle_tasks
put(task)
File "/usr/lib/python3.5/multiprocessing/connection.py", line 206, in send
self._send_bytes(ForkingPickler.dumps(obj))
File "/usr/lib/python3.5/multiprocessing/reduction.py", line 50, in dumps
cls(buf, protocol).dump(obj)
TypeError: can't pickle generator objects
答案 0 :(得分:0)
在fit_generator中设置use_multiprocessing = False,这可以解决该问题。
答案 1 :(得分:-3)
更新
嵌套在我strat
课程深处的3个对象我有一个我忘记的生成器。