Value的第一个参数是typecode_or_type.这被定义为:
typecode_or_type determines the type of the returned object: it is
either a ctypes type or a one character typecode of the kind used by
the array module. *args is passed on to the constructor for the type.
强调我的所以,你根本不能把一个熊猫数据框放在一个值,它必须是a ctypes type.
您可以使用multiprocessing.Manager将您的单例数据帧实例提供给所有进程.有几种不同的方式在同一个地方结束 – 可能最简单的方法是将数据框放在经理的命名空间中.
from multiprocessing import Manager
mgr = Manager()
ns = mgr.Namespace()
ns.df = my_dataframe
# now just give your processes access to ns, i.e. most simply
# p = Process(target=worker, args=(ns, work_unit))
现在,您的数据框实例可以被任何通过对Manager的引用的进程访问.或者只是传递对命名空间的引用,它更干净.
我没有/不会覆盖的一件事是事件和信号 – 如果您的进程需要等待其他人完成执行,则需要在Here is a page中添加一些事件示例,其中还包含一些更详细的信息如何使用经理的命名空间.
(请注意,没有一个解决多处理是否会产生实际的性能优势,这只是给您工具来探索这个问题)