Hello i have created a script in python to run with PM2 a process monitoring tool available in NPM, the code is taken from the accepted answer of this question and is following
import signal
import sys
import time
def signal_handler(sig, frame):
print('You pressed Ctrl+C!')
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
print('Press Ctrl+C to exit')
while True:
time.sleep(0.2)
NOTE: signal.pause() is not available for windows so i used infinite loop as an alternative (code blocking)
Now coming to the problem when I run the script manually from the CMD e.g., py test.py
and then after pressing CTRL + C it captures the SIGINT perfectly, but when the same script is executed with PM2 e.g., pm2 start "py test.py" --name SigTestApp
then stopping the PM2 process by typing pm2 stop SigTestApp
simply kills the app and SIGINT is not being detected by the script
e.g., no message is shown "You pressed Ctrl+C!"