Skip to content

Commit add492c

Browse files
committed
Show the signal name instead of the number
1 parent 4f585c1 commit add492c

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

pyrogram/methods/utilities/idle.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,19 @@
1818

1919
import asyncio
2020
import logging
21-
from signal import signal, SIGINT, SIGTERM, SIGABRT
21+
import signal
22+
from signal import signal as signal_fn, SIGINT, SIGTERM, SIGABRT
2223

2324
log = logging.getLogger(__name__)
2425

2526
is_idling = False
2627

28+
# Signal number to name
29+
signals = {
30+
k: v for v, k in signal.__dict__.items()
31+
if v.startswith("SIG") and not v.startswith("SIG_")
32+
}
33+
2734

2835
async def idle():
2936
"""Block the main script execution until a signal is received.
@@ -65,14 +72,14 @@ async def idle():
6572
"""
6673
global is_idling
6774

68-
def signal_handler(_, __):
75+
def signal_handler(signum, __):
6976
global is_idling
7077

71-
logging.info("Stop signal received ({}). Exiting...".format(_))
78+
logging.info(f"Stop signal received ({signals[signum]}). Exiting...")
7279
is_idling = False
7380

7481
for s in (SIGINT, SIGTERM, SIGABRT):
75-
signal(s, signal_handler)
82+
signal_fn(s, signal_handler)
7683

7784
is_idling = True
7885

0 commit comments

Comments
 (0)