I have a python program that runs another python script in a subprocess (yes I know this architecture is not ideal but the nature of the project makes it necessary). I am trying to:
1. send a sigint to the python subprocess (simulate a keyboard kill)
2. catch the sigint in the subprocess and perform some cleanup before exit
The code follows this general pattern:
A.py
import signal
import subprocess
import time
proc = subprocess.Popen('python B.py', shell=True)
time.sleep(1)
proc.send_signal(signal.SIGINT)
B.py
try:
while True:
# some application logic
pass
except:
# some cleanup logic
print('bye')
But when I run A.py, B.py never receives the signal or does it's cleanup logic. Any idea what is going on here?