Skip to content

Commit

Permalink
Add try-except to catch ReferenceError during searching the server ob…
Browse files Browse the repository at this point in the history
…ject (#1042)

* Add try-except to catch ReferenceError during searching the server object

* Update CHANGELOG.md
  • Loading branch information
whitphx authored Aug 31, 2022
1 parent 16c9488 commit 6af99ea
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion streamlit_webrtc/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 6af99ea

Please sign in to comment.