add delay in connection_handler to ensure resources are freed before process restart

This commit is contained in:
vvzvlad
2025-06-10 03:38:33 +03:00
parent 0f992bf3a8
commit 223ae57929
+6
View File
@@ -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: