views:

65

answers:

1

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 Queue

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.

+1  A: 

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).

Jeremy Brown