【问题标题】:How to start and stop subprocess from flask [duplicate]如何从烧瓶中启动和停止子进程[重复]
【发布时间】:2019-12-16 15:57:50
【问题描述】:

我有一个烧瓶应用程序,我需要从中启动几个其他应用程序(webrtc 聊天。) 我可以使用 gunicorn 轻松完成,但我的问题是如何启动 5-10-15 或更多 webrtc 应用程序(可以使用 gunicorn 命令执行此操作)然后停止其中一些但不是全部。

所以有了这个:

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

启动服务器的命令,每个管理器都会在自己的端口上启动一个服务器,这里没有问题。但是,当管理器不再需要服务器时,如何存储一个进程然后杀死它?我不知道——有什么建议吗?

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

所以我可以使用上面的命令启动服务器,但不知道如何存储然后杀死进程, 感谢您的时间和帮助!

【问题讨论】:

    标签: python flask subprocess


    【解决方案1】:

    如果有人需要,How to terminate a python subprocess launched with shell=True 的想法似乎可行

    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)
    

    【讨论】:

      猜你喜欢
      • 2019-08-14
      • 1970-01-01
      • 2011-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-26
      • 1970-01-01
      相关资源
      最近更新 更多