From 223ae579296b88169d73b8ae4257e59a45b6533a Mon Sep 17 00:00:00 2001 From: vvzvlad Date: Tue, 10 Jun 2025 03:38:33 +0300 Subject: [PATCH] add delay in connection_handler to ensure resources are freed before process restart --- telegram_client.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/telegram_client.py b/telegram_client.py index 21f24a1..5d8c1a9 100644 --- a/telegram_client.py +++ b/telegram_client.py @@ -14,6 +14,7 @@ import asyncio import sys import signal import uvloop +import time asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) from pyrogram import Client @@ -79,6 +80,11 @@ class TelegramClient: if loop.is_running(): loop.create_task(self.stop()) + # Добавляем задержку, чтобы предыдущий процесс успел завершиться + # и освободить порт и другие ресурсы + logger.info("connection_handler: waiting for resources to be freed before restart") + time.sleep(3) + # Use os.execv to restart the process with the same arguments os.execv(sys.executable, [sys.executable] + sys.argv) except Exception as e: