的序列化ctypes.结构在Python中

2024-10-02 22:25:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用ctypes来处理Python包装器。修改制造商给出的示例,我将帧作为ctypes.结构对象,工作正常。但此对象无法序列化,因此无法为单独的进程设置队列。我试着用基于dill的感伤:

import ctypes
from pathos.helpers import mp
import time

#Define point structure
class HeliosPoint(ctypes.Structure):
    #_pack_=1
    # projector maximum seems to be uint12
    _fields_ = [('x', ctypes.c_uint16),
                ('y', ctypes.c_uint16),
                ('r', ctypes.c_uint8),
                ('g', ctypes.c_uint8),
                ('b', ctypes.c_uint8),
                ('i', ctypes.c_uint8)]
frameType = HeliosPoint * 1000

def fill_queue_with_frames(Qf):
    while 1:
        frame = frameType()
        Qf.put(frame)

frame_q = mp.Queue(1000)

ProcessB = mp.Process(target=fill_queue_with_frames, args=(frame_q,))
ProcessB.start()

使用pathos,我得到以下错误:

^{pr2}$

这能解决吗?有没有其他方法可以在不序列化的情况下设置两个并发进程?在


Tags: 对象import序列化queue进程withmpctypes