From add492c1bea8668c0c5c7b50bcc63bbdc85972ef Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 15 Apr 2021 12:04:43 +0200 Subject: [PATCH] Show the signal name instead of the number --- pyrogram/methods/utilities/idle.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/pyrogram/methods/utilities/idle.py b/pyrogram/methods/utilities/idle.py index ba332650..7b41f7af 100644 --- a/pyrogram/methods/utilities/idle.py +++ b/pyrogram/methods/utilities/idle.py @@ -18,12 +18,19 @@ import asyncio import logging -from signal import signal, SIGINT, SIGTERM, SIGABRT +import signal +from signal import signal as signal_fn, SIGINT, SIGTERM, SIGABRT log = logging.getLogger(__name__) is_idling = False +# Signal number to name +signals = { + k: v for v, k in signal.__dict__.items() + if v.startswith("SIG") and not v.startswith("SIG_") +} + async def idle(): """Block the main script execution until a signal is received. @@ -65,14 +72,14 @@ async def idle(): """ global is_idling - def signal_handler(_, __): + def signal_handler(signum, __): global is_idling - logging.info("Stop signal received ({}). Exiting...".format(_)) + logging.info(f"Stop signal received ({signals[signum]}). Exiting...") is_idling = False for s in (SIGINT, SIGTERM, SIGABRT): - signal(s, signal_handler) + signal_fn(s, signal_handler) is_idling = True