for p in all_processes:
    p_sec = 0
for second in range(timeout_sec):
    if p.poll() == None:
        time.sleep(1)
p_sec += 1
if p_sec >= timeout_sec:
    p.kill()
print('cleaned up!')
atexit.register(cleanup)
sys.exit()
Ensuring subprocesses are dead on exiting Python program