Skip to content

Commit

Permalink
Fix Python 3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
brentyi committed Nov 2, 2024
1 parent 5151135 commit 8657855
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/viser/infra/_infra.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def __init__(
self._client_api_version: Literal[0, 1] = client_api_version
self._background_event_loop: asyncio.AbstractEventLoop | None = None

self._stop_event = asyncio.Event()
self._stop_event: asyncio.Event | None = None

self._client_state_from_id: dict[int, _ClientHandleState] = {}

Expand All @@ -262,6 +262,7 @@ def start(self) -> None:
def stop(self) -> None:
"""Stop the server."""
assert self._background_event_loop is not None
assert self._stop_event is not None
self._background_event_loop.call_soon_threadsafe(self._stop_event.set)

def on_client_connect(
Expand Down Expand Up @@ -300,6 +301,7 @@ def _background_worker(self, ready_sem: threading.Semaphore) -> None:
# Need to make a new event loop for notebook compatbility.
event_loop = asyncio.new_event_loop()
asyncio.set_event_loop(event_loop)
self._stop_event = asyncio.Event()
self._background_event_loop = event_loop
self._broadcast_buffer = AsyncMessageBuffer(
event_loop, persistent_messages=True
Expand Down Expand Up @@ -502,6 +504,7 @@ async def start_server() -> None:
assert serve_future.server is not None
self._port = port_attempt
ready_sem.release()
assert self._stop_event is not None
await self._stop_event.wait()
return
except OSError: # Port not available.
Expand Down

0 comments on commit 8657855

Please sign in to comment.