How to kill child processes & grandchild processes controlled by supervisor

1.6k Views Asked by At

In a process controlled by Supervisor, I fork child process

for i in xrange(MANAGER_PROCESS_NUM):
    p = gipc.start_process(target=daemon_process, args=())
    record.append(p)
for r in record:
    r.join()

then in each child process, I create grandchild process:

w = gipc.start_process(target=self._pool_worker, daemon=True)

How can I kill all the child processes & grandchild processes when I run "supervisorctl stop xxx" to stop my main process?

1

There are 1 best solutions below

3
On

You have a couple options:

  1. Modify your Python programs so that when they receive signals like SIGTERM they propagate them to the children explicitly.

  2. Enable the supervisord options stopasgroup and killasgroup. These options are documented as sending signals to the entire process group rather than just one process.