Skip to content

Commit

Permalink
Python Client: avoid thread self-join on stop()
Browse files Browse the repository at this point in the history
  • Loading branch information
kosak committed Jan 3, 2024
1 parent e860064 commit 393b228
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions py/client-ticking/src/pydeephaven_ticking/table_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,24 +211,29 @@ def start(self) -> None:

def stop(self) -> None:
"""Cancels the subscription to the table and stops the service thread. By the time this method returns, the
thread servicing the subscription will be destroyed, and the callback will no longer be invoked."""
thread servicing the subscription will be destroyed, and the callback will no longer be invoked.
This method joins the subscription servicing thread, unless stop() was called from that very thread.
This can happen if the user's callback calls stop()."""

self._cancelled = True
self._reader.cancel()
self._thread.join()
if threading.get_ident() != self._thread.ident:
self._thread.join()

def _process_data(self):
"""This method continuously runs on a separate thread. It processes incoming Barrage messages, feeds them to
the BarrageProcessor library, and, when the BarrageProcessor library produces a TableUpdate, calls the
user-supplied callback with that TableUpdate."""

try:
while True:
while not self._cancelled:
data, metadata = self._reader.read_chunk()
ticking_update = self._bp.process_next_chunk(data.columns, metadata)
if ticking_update is not None:
table_update = TableUpdate(ticking_update)
self._listener.on_update(table_update)
except StopIteration:
pass
except Exception as e:
if not self._cancelled:
self._listener.on_error(e)
Expand Down

0 comments on commit 393b228

Please sign in to comment.