0

I have a flask app, from which I need to start few other apps (webrtc chats.) I can easily do it with gunicorn, but my problem is how to start 5-10-15 or more webrtc apps( can do this with gunicorn command) and then stop some of them but not all.

So with this:

gunicorn --worker-class eventlet -w 1 --certfile /path/to/file --keyfile /path/to/file -b 0.0.0.0:8000 wsgi:app

command to start the server, each manager will start a server on its own port, no problems here. But how to store a process and then kill it, when the manager no longer needs server? I have no idea--any tips?

args = 'exec ' + gunicorn_command_above
p = subprocess.Popen(args, stdout=subprocess.PIPE, shell=True)

So i can start servers with commands above, but don't know how to store and then kill process, thx for your time and help!

aschultz
  • 1,658
  • 3
  • 20
  • 30
Bill Johan
  • 83
  • 1
  • 7

1 Answers1

1

If someone need, seems idea from How to terminate a python subprocess launched with shell=True works

p = subprocess.Popen("exec " + cmd, stdout=subprocess.PIPE, shell=True, preexec_fn=os.setsid)
# and after, we can kill this group with
os.killpg(os.getpgid(p.pid), signal.SIGTERM)
Bill Johan
  • 83
  • 1
  • 7