从多处理队列中提取参数

时间:2020-06-30 12:57:34

标签: python multiprocessing

我通过以下方式定义了QueuePool

self.thread_queue = multiprocessing.Queue()
self.thread_pool = multiprocessing.Pool(workers, self.applyAndAddSonsToQueue,(self.thread_queue,) )

applyAndAddSonsToQueue的实现是:

    def applyAndAddSonsToQueue(self,node,command):
        f = command[0]
        args = command[1:]
        try:
            logging.info(f" started process running {f}({*args,})")
            res = f(*args)
            logging.info(f" finished process running {f}({*args,})")

            self.finished_nodes.append(node)
            for son_node in self.specification_graph.successors(node):
                if all(self.specification_graph.predecessors(son_node) in self.finished_nodes):
                    self.thread_queue.put(son_node,*self.command_registry[son_node])

        except Exception as e:
            logging.info(f" Caught exception in worker process running {f}({*args,})")

            traceback.print_exc()
            raise e

我遇到了以下问题:

Traceback (most recent call last):
  File "/home/eliran/miniconda/envs/newenv/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
    self.run()
  File "/home/eliran/miniconda/envs/newenv/lib/python3.7/multiprocessing/process.py", line 99, in run
    self._target(*self._args, **self._kwargs)
  File "/home/eliran/miniconda/envs/newenv/lib/python3.7/multiprocessing/pool.py", line 105, in worker
    initializer(*initargs)
TypeError: applyAndAddSonsToQueue() missing 1 required positional argument: 'command'

我的猜测是,我应该只对applyAndAddSonsToQueue队列提出争论,但不确定如何提取此功能所需的争论。

我希望这个问题不太具体,如果您觉得需要更多信息来回答这个问题,请告诉我。

编辑:假设我以这种方式将事物放入队列:

self.thread_queue.put(root, *self.arg_dict[root])

当我打电话给queue.get()时,我应该期待什么对象?它是一个元组吗?清单?单一值?

0 个答案:

没有答案
相关问题