소스 검색

handle exceptions during send_json to avoid lots of tracebacks flooding the console output

Falko Schindler 3 년 전
부모
커밋
e7fdd6316b
1개의 변경된 파일8개의 추가작업 그리고 0개의 파일을 삭제
  1. 8 0
      nicegui/elements/scene.py

+ 8 - 0
nicegui/elements/scene.py

@@ -1,5 +1,6 @@
 from typing import Awaitable, Callable, Optional, Union
 import traceback
+import websockets
 from .element import Element
 from .custom_view import CustomView
 from .page import Page
@@ -33,6 +34,13 @@ class SceneView(CustomView):
         except:
             traceback.print_exc()
 
+    async def run_method(self, command, websocket):
+        try:
+            await websocket.send_json({'type': 'run_method', 'data': command, 'id': self.id})
+        except (websockets.exceptions.ConnectionClosedOK, RuntimeError):
+            pass
+        return True
+
 class Scene(Element):
     from .scene_objects import Group as group
     from .scene_objects import Box as box