From 6af99eaa2d41f82a5e78236ede238adbfa86bbfb Mon Sep 17 00:00:00 2001 From: "Yuichiro Tachibana (Tsuchiya)" Date: Thu, 1 Sep 2022 01:40:54 +0900 Subject: [PATCH] Add try-except to catch ReferenceError during searching the server object (#1042) * Add try-except to catch ReferenceError during searching the server object * Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ streamlit_webrtc/server.py | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db5f561d..64e6e309 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +### Fix + +- Catch `ReferenceError` during searching the server object , #1042. + ## [0.43.2] - 2022-08-27 ### Fix diff --git a/streamlit_webrtc/server.py b/streamlit_webrtc/server.py index e48bdce0..e9ab72b7 100644 --- a/streamlit_webrtc/server.py +++ b/streamlit_webrtc/server.py @@ -49,7 +49,13 @@ def get_current_server(): from streamlit.web.server.server import Server - servers = [obj for obj in gc.get_objects() if isinstance(obj, Server)] + def is_server(obj) -> bool: + try: + return isinstance(obj, Server) + except ReferenceError: # This is necessary due to https://github.com/whitphx/streamlit-webrtc/issues/1040 # noqa: E501 + return False + + servers = [obj for obj in gc.get_objects() if is_server(obj)] if len(servers) == 0: raise RuntimeError("Unexpectedly no server exists")