0

I have a flask app with 3 functions, one of the function is in a subprocess, and I am killing that subprocess using os.killpg, but when the program executes os.killpg, the command is terminating the flask app itself. I want to just terminate the subprocess, not flask app. Can you please help with this?

flask import Flask, Response, request, jsonify
import subprocess
import time
import os
import signal

app = Flask(__name__)

@app.route("/cam", methods=['POST'])
def cam():

    cmd3 = "gst-launch-1.0 -v v4l2src ! video/x-raw,format=YUY2 ! 
                  videoconvert ! autovideosink"
    process3 = subprocess.Popen(cmd3, shell = True)
    time.sleep(1)
    os.killpg(os.getpgid(process3.pid), signal.SIGTERM)

@app.route("/one", methods=['POST'])
def one():
    " some commands
    "

@app.route("/two", methods=['POST'])
def two():
    " some commands
    "

if __name__ == "__main__":

    app.run(debug=True, host='0.0.0.0', port = 6005)
Mahima K
  • 85
  • 2
  • 11

0 Answers0