Unitech / Unitech/pm2

pm2 fail to output print after sleep(10) when receveing a sigint

Open
#5,947 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
43.3k
Forks
2.7k
PR merge metrics
No merged PRs in 30d

Description

import signal
import time
import sys

def signal_handler(signum, frame):
    time.sleep(10)
    print('\nSignal received, Exit......')
    sys.exit(0)

signal.signal(signal.SIGINT, signal_handler)

count = 0
try:
    while True:
        print(f'count: {count}')
        count += 1
        time.sleep(1)
except KeyboardInterrupt:
    print('\nProgram Exit')

When I press Ctrl + C in the terminal, the message Signal received, Exit...... appears after 10 seconds.

(ccxt) (base) ➜  zmqmsg python test_pm2_sig.py 
count: 0
count: 1
count: 2
^C
Signal received, Exit......

However, when I start the program with pm2 and stop it using pm2 stop, it does not print '\nSignal received, Exit......'.

21|pm2_sig | count: 0
21|pm2_sig | count: 1
21|pm2_sig | count: 2
21|pm2_sig | count: 3
21|pm2_sig | count: 4
21|pm2_sig | count: 5
21|pm2_sig | count: 6
21|pm2_sig | count: 7
21|pm2_sig | count: 8
21|pm2_sig | count: 9
21|pm2_sig | count: 10
21|pm2_sig | count: 11
21|pm2_sig | count: 12

I am running on Linux Ubuntu which supports sigint.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the provided Python script under pm2 on Ubuntu and compare pm2 stop with terminal Ctrl-C signal handling. Done means identifying why the delayed signal-handler output is missing and documenting or correcting the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
linux, node.js, python
Domain
cli, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.