From 465f7c41482a2e1f217113b34313162a2036c397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=9B=E6=B0=B4=E5=B1=85=E5=AE=A4?= Date: Sat, 22 Oct 2022 15:48:53 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20=E6=B7=BB=E5=8A=A0=E8=B6=85?= =?UTF-8?q?=E6=97=B6=E9=85=8D=E7=BD=AE=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 7 +++++++ core/bot.py | 9 ++++++++- core/config.py | 6 ++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index a21c906..a187cf4 100644 --- a/.env.example +++ b/.env.example @@ -46,6 +46,13 @@ LOGGER_LOCALS_MAX_DEPTH=0 LOGGER_LOCALS_MAX_LENGTH=10 LOGGER_LOCALS_MAX_STRING=80 +# 超时配置 可选配置项 +# TIMEOUT = 10 +# READ_TIMEOUT = 2 +# WRITE_TIMEOUT = 10 +# CONNECT_TIMEOUT = 10 +# POOL_TIMEOUT = 10 + # mtp 客户端 可选配置项 # API_ID=12345 # API_HASH="abcdefg" diff --git a/core/bot.py b/core/bot.py index d923e2a..4d43cee 100644 --- a/core/bot.py +++ b/core/bot.py @@ -243,7 +243,14 @@ class Bot: try: for _ in range(5): try: - self.app.run_polling(close_loop=False, write_timeout=10) + self.app.run_polling( + close_loop=False, + timeout=self.config.timeout, + read_timeout=self.config.read_timeout, + write_timeout=self.config.write_timeout, + connect_timeout=self.config.connect_timeout, + pool_timeout=self.config.pool_timeout, + ) break except TimedOut: logger.warning("连接至 [blue]telegram[/] 服务器失败,正在重试", extra={"markup": True}) diff --git a/core/config.py b/core/config.py index c97e6d2..4e24be7 100644 --- a/core/config.py +++ b/core/config.py @@ -57,6 +57,12 @@ class BotConfig(BaseSettings): logger_locals_max_length: int = 10 logger_locals_max_string: int = 80 + timeout: int = 10 + read_timeout: float = 2 + write_timeout: Optional[float] = None + connect_timeout: Optional[float] = None + pool_timeout: Optional[float] = None + enka_network_api_agent: str = "" pass_challenge_api: str = "" pass_challenge_app_key: str = ""