How to call process by name or tags in python
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
- Initiator Process name
- 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).
精彩评论