Sorry...it似乎问了一个很受欢迎的问题,但我从堆栈流中找不到对我的情况有任何帮助的问题:P
因此,我的代码执行以下操作:
步骤1.父进程将任务对象写入multiprocessing.JoinableQueue
步骤2.子进程(多于1)从JoinableQueue读取(获取)任务对象并执行任务
我的模块结构是:
A.py
- def run() # here the step 2 is executed
- def loadTest() # here the step 1 above is executed, i.e. append the object of Task
我所理解的是,当使用mp.JoinableQueue时,附加的对象应该是可选择的,我从https://docs.python.org/2/library/pickle.html#what-can-be-pickled-and-unpickled得到了“可选择”的含义。
我的问题是: 1.任务的对象在我的情况下是可选择的吗?
2014-06-23 03:18:43 INFO TestGroup: G1末端负载测试: object1
2014-06-23 03:18:43 INFO TestGroup: G1末端负载测试: object2
2014-06-23 03:18:43 INFO TestGroup: G1末端负载测试: object3发送(Obj)
pysphere.resources.VimService_services_types.DynamicData_Holder :无法选择:属性查找失败
发布于 2014-06-24 02:30:32
Python中的multiprocessing模块启动多个进程来运行任务。由于进程不共享内存,因此它们需要能够使用序列化数据进行通信。多处理使用泡菜模块进行序列化,因此您要传递给任务的对象必须是可选择的。
1)您的任务对象似乎包含来自pysphere.resource.VimService_services_types的一个实例。这可能是对系统资源(例如打开的文件)的引用。这不能序列化或从一个进程传递到另一个进程,因此它会导致酸洗错误。
您可以使用mp.JoinableQueue将所需的参数传递给任务,并让它在任务本身中启动服务,使其成为该进程的本地服务。
例如:
queue = mp.JoinableQueue()
# not queue.put(task), since the new process will create the task
queue.put(task_args)
def f(task_args):
task = Task(task_args)
...
# you can't return the task, unless you've closed all non-serializable parts
return task.result
process = Process(target=f, args=(queue,))
... 2) Queue.Queue是用于线程处理的。它使用共享内存和同步机制来提供原子操作。但是,当您使用多进程启动一个新进程时,它会复制初始进程,因此每个子进程都将处理相同的队列对象,因为每个进程的内存中的队列都已被复制。
https://stackoverflow.com/questions/24364154
复制相似问题