refactor api_server and TelegramClient: remove force_exit function and replace with sys.exit for process termination, update restart logic to use SIGTERM instead of SIGKILL for graceful shutdown

This commit is contained in:
vvzvlad
2025-06-10 15:03:09 +03:00
parent 521c3dc394
commit 43516d6dab
2 changed files with 7 additions and 26 deletions
+5 -5
View File
@@ -72,12 +72,12 @@ class TelegramClient:
raise
def _restart_app(self):
"""Restarts the application by forcefully killing the process to trigger Docker container restart"""
logger.warning("connection_handler: restarting application by forceful termination")
"""Restarts the application by sending SIGTERM to the process"""
logger.warning("connection_handler: restarting application by sending SIGTERM")
try:
# Forcefully kill the process using SIGKILL to ensure immediate termination
logger.critical("connection_handler: sending SIGKILL to self")
os.kill(os.getpid(), signal.SIGKILL)
# Use SIGTERM for proper Docker container restart
logger.critical("connection_handler: sending SIGTERM signal")
os.kill(os.getpid(), signal.SIGTERM)
except Exception as e:
logger.error(f"connection_handler: error during restart: {str(e)}")
# Emergency termination