开发者

How to call process by name or tags in python

开发者 https://www.devze.com 2023-01-06 06:38 出处:网络
I am using multiprocessing module. This module is works on Queue that is its pick random process and assign the entery from Queue.

I am using multiprocessing module. This module is works on Queue that is its pick random process and assign the entery from Queue.

I want to decide which process will work on which entry of Queu开发者_如何学运维e

Here is my requirements,

I will pass 2 parameters to queue

  1. Initiator Process name
  2. Action/method ( What process is going to do)

Its should pass queue Entry to given Process only.


multiprocessing.Process objects take an optional name argument on initialization. You can use that name as a key in a dictionary:

child_procs = {'name1' : Process(target=myprocfunc, name='name1'), ...}

As for IPC between the parent process and the children, you should be fine with just maintaining a separate multiprocessing.Queue for each child process. You'll need a task distribution object/function to assign work. This function would probably be responsible for popping the task from the main/central queue and then assigning it to the correct child process queue (based on the architecture I am gleaming from your question).

0

精彩评论

暂无评论...
验证码 换一张
取 消