Skip to content

Try to stop the bridge on shutdown #253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions resonate/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,18 +166,23 @@ def start(self) -> None:
self._delay_thread.start()

def stop(self) -> None:
self._message_src.stop()
self._cq.put_nowait(None)
self._mq.put_nowait(None)
self._heartbeat_active.clear()
self._shutdown.set()
"""Stop internal components and threads. Intended for use only within the resonate class."""
self._stop_no_join()
if self._bridge_thread.is_alive():
self._bridge_thread.join()
if self._messages_thread.is_alive():
self._messages_thread.join()
if self._heartbeat_thread.is_alive():
self._heartbeat_thread.join()

def _stop_no_join(self) -> None:
"""Stop internal components and threads. Does not join the threads, to be able to call it from the bridge itself."""
self._message_src.stop()
self._cq.put_nowait(None)
self._mq.put_nowait(None)
self._heartbeat_active.clear()
self._shutdown.set()

@exit_on_exception
def _process_cq(self) -> None:
while True:
Expand Down Expand Up @@ -206,6 +211,7 @@ def _process_cq(self) -> None:

# bypass the cq and shutdown right away
self._scheduler.shutdown(err)
self._stop_no_join()
return

case Function(id, cid, func):
Expand Down
Loading