From 393b228efdcf31280aebf9f8d10f01673ffc2aba Mon Sep 17 00:00:00 2001 From: Corey Kosak Date: Mon, 1 Jan 2024 16:39:07 -0500 Subject: [PATCH] Python Client: avoid thread self-join on stop() --- .../src/pydeephaven_ticking/table_listener.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/py/client-ticking/src/pydeephaven_ticking/table_listener.py b/py/client-ticking/src/pydeephaven_ticking/table_listener.py index 8397b98149d..6bcbbfbf282 100644 --- a/py/client-ticking/src/pydeephaven_ticking/table_listener.py +++ b/py/client-ticking/src/pydeephaven_ticking/table_listener.py @@ -211,11 +211,14 @@ 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 @@ -223,12 +226,14 @@ def _process_data(self): 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)