using python multiprocessing to control independent background workers after the spawning process has been closed -


i see lot of examples of how use multiprocessing talk spawning workers , controlling them while main process alive. question how control background workers in following way:

start 5 worker command line:

  • manager.py --start 5

after that, able list , stop workers on demand command line:

  • manager.py --start 1 #will add 1 more worker
  • manager.py --list
  • manager.py --stop 2
  • manager.py --sendmessagetoall "hello"
  • manager.py --stopall

the important point manager.py should exit after every run. don't understand how list of running workers newly created manager.py program , communicate them.

edit: bilkokuya suggested have (1)a manager process manage list of workers... , listen incoming commands. , (2) small command line tool send messages first manager process... sounds solution. still, question remains same - how communicate process on newly created command line program (process 2)? examples see (of queue example) works when both processes running time

the portable solution can suggest (although still involve further research you), have long-running process manages "background worker" processes. shouldn't ever killed off, handles logic piping messages each sub process.

manager.py can implement logic create communication long-running process (whether that's via pipes, sockets, http or other method like). manager.py passes on message 'server' process "hey please stop child processes" or "please send message process 10" etc.

there lot of work involved in this, , lot research. main thing you'll want how handle ipc (inter-process communication). allow manager.py script interact existing/long-running process can better manage each background worker.

the alternative rely on operating system's process management apis. i'd suggest experience more error prone , troublesome solution.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -