0

I have an python module called app.py which has the following code

if __name__ == "__main__":    
    for _ in range(settings.DJANGO_RQ_WORKERS):
        # spawn up non-blocking rq worker
        subprocess.Popen(
            [
                sys.executable,
                "manage.py",
                "rqworker"
            ],
            stdout=subprocess.PIPE,
        )
    # spawn up non-blocking rq scheduler
    subprocess.Popen(
        [
            sys.executable,
            "manage.py",
            "rqscheduler"
        ],
        stdout=subprocess.PIPE,
    )
    subprocess.check_call(
        [
            "gunicorn",
            "--bind",
            args.bind_address,
            "chilli.wsgi:application",
            "--workers",
            '2',
            "--threads",
            "2",
        ],
        env=dict(os.environ),
        cwd=os.getcwd(),
        stdout=subprocess.PIPE,
    )

I am running file as python app.py and ps -ef | grep python yields

503 96626 37650   0  4:21pm ttys006    0:00.80 python application.py
503 96629 96626   0  4:21pm ttys006    0:00.91 python manage.py rqworker
503 96630 96626   0  4:21pm ttys006    0:00.90 python manage.py rqscheduler
503 96631 96626   0  4:21pm ttys006    0:00.22 python gunicorn --bind 0.0.0.0:8080 chilli.wsgi:application --workers 2 --threads 2
503 96632 96631   0  4:21pm ttys006    0:00.62 python gunicorn --bind 0.0.0.0:8080 chilli.wsgi:application --workers 2 --threads 2
503 96633 96631   0  4:21pm ttys006    0:00.61 python gunicorn --bind 0.0.0.0:8080 chilli.wsgi:application --workers 2 --threads 2

but when I send kill -15 96626 (pid of application.py) only this process terminate and the rest of the process run in background. How do I kill all the subprocess spawned when I send SIGTERM to my main module?

jebaseelan ravi
  • 185
  • 2
  • 10

1 Answers1

0

If you want to send a signal to all process group, you need to use pgid() value with "-" prefix. In your case, it would be kill -15 -96626

Veysel Olgun
  • 552
  • 1
  • 3
  • 15