1

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!"

Zain Ul Abidin
  • 2,467
  • 1
  • 17
  • 29
  • I have exact same problem since 2 months - When I do `pm2 stop `, SIGINT is not received by my python process. And this is critical for me since my program is interfacing with some third party devices that are not under my control. Still looking for a solution! – Ananth Nov 30 '22 at 07:36

0 Answers0