I have a Python server that starts multiple subprocesses via subprocess.Popen()
. When I run a specific method on the server, I want to terminate all of these processes.
My approach to this was to keep references to all processes in a list ...
self.procs.append(subprocess.Popen(shlex.split(cmd)))
... and send interrupts to all of these to shut them down:
for i, p in enumerate(self.procs) :
p.send_signal(signal.SIGINT)
print 'interrupted ' + str(i)
self.procs = []
However, this only works for some of the subprocesses. For instance, one of the processes that does not stop after this call is a bash script that has a trap
function for SIGINT signals. If I manually start this script and interrupt it via keyboard, it correctly executes the trap statement and closes . When the server sends the signal instead, the script seems to keep running.
What could be going wrong here?
edit: I have also tried using the SIGTERM signal instead, which did not work either.