From e9d4bf47cf359400f0653b9a796438669bbd7e4d Mon Sep 17 00:00:00 2001 From: John Smith Date: Tue, 5 Sep 2023 19:23:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A2=E6=88=B7=E7=AB=AF=E6=AD=A3=E5=B8=B8?= =?UTF-8?q?=E5=81=9C=E6=AD=A2=E4=B9=9F=E8=B0=83=E7=94=A8=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blivedm/clients/ws_base.py | 6 ++++-- blivedm/handlers.py | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/blivedm/clients/ws_base.py b/blivedm/clients/ws_base.py index da21755..3387bdb 100644 --- a/blivedm/clients/ws_base.py +++ b/blivedm/clients/ws_base.py @@ -232,8 +232,8 @@ class WebSocketClientBase: logger.debug('room=%s _network_coroutine() finished', self.room_id) self._network_future = None - if exc is not None and self._handler is not None: - self._handler.on_stopped_by_exception(self, exc) + if self._handler is not None: + self._handler.on_client_stopped(self, exc) async def _network_coroutine(self): """ @@ -454,6 +454,8 @@ class WebSocketClientBase: :param command: 业务消息 """ + if self._handler is None: + return try: # 为什么不做成异步的: # 1. 为了保持处理消息的顺序,这里不使用call_soon、create_task等方法延迟处理 diff --git a/blivedm/handlers.py b/blivedm/handlers.py index c53cea6..9d33b70 100644 --- a/blivedm/handlers.py +++ b/blivedm/handlers.py @@ -48,9 +48,9 @@ class HandlerInterface: def handle(self, client: ws_base.WebSocketClientBase, command: dict): raise NotImplementedError - def on_stopped_by_exception(self, client: ws_base.WebSocketClientBase, exception: Exception): + def on_client_stopped(self, client: ws_base.WebSocketClientBase, exception: Optional[Exception]): """ - 当客户端被异常停止时调用。可以在这里close或者重新start + 当客户端停止时调用。可以在这里close或者重新start """