for proc in current_subprocs:
    if proc.poll() is None:
        proc.send_signal(signum)
signal.signal(signal.SIGINT, handle_signal)
signal.signal(signal.SIGTERM, handle_signal)
for _ in range(10):
    if shutdown:
        break
cmd = ['sleep', '2']
p = Popen(cmd, stdout=PIPE, stderr=PIPE)
current_subprocs.add(p)
out, err = p.communicate()
current_subprocs.remove(p)
print('subproc returncode', p.returncode)
Making sure a Python script with subprocesses dies on SIGINT