如果子进程是由WSGI脚本创建的,则不会退出

时间:2019-10-29 16:52:00

标签: python subprocess wsgi

我有一个来自Web应用程序的代码段,如果我从命令行执行此代码段,则可以正常运行并退出。但是,如果它是由http请求发出的,则子进程将不会退出。

import subprocess


def test_build():
    msg = 'msg'
    make_code = '/opt/arduino/arduino-builder -compile -and-many-other-options -verbose /tmp/arduino-sketch-7c17cb3749d67dadaded5c7edc6ca63b/main.ino'
    try:
        ps = subprocess.Popen(make_code,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
        msg = ps.stderr.read()
        exc_code = ps.wait()
        # print(msg) # for debug only
        # print(exc_code)
    except Exception as e:
        print("error with build", str(e) + msg)

test_build()

仅当向main.ino添加特定代码时,此发生。

subprocess.Popen(make_code,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)更改为subprocess.Popen(make_code,stderr=subprocess.PIPE,shell=True)后,问题消失了,但是我不知道为什么会发生这种情况。

如果子流程是由Web应用派生的,子流程是否有任何区别?

0 个答案:

没有答案