From 60d15bbe2a638fe85ccc73f89ef73f65dae567e9 Mon Sep 17 00:00:00 2001 From: Joe Numainville Date: Fri, 19 Apr 2024 14:45:53 -0500 Subject: [PATCH 1/3] exit on communication failure --- .../deephaven/ui/object_types/ElementMessageStream.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/plugins/ui/src/deephaven/ui/object_types/ElementMessageStream.py b/plugins/ui/src/deephaven/ui/object_types/ElementMessageStream.py index 5d4d1c593..474b16ad1 100644 --- a/plugins/ui/src/deephaven/ui/object_types/ElementMessageStream.py +++ b/plugins/ui/src/deephaven/ui/object_types/ElementMessageStream.py @@ -2,6 +2,8 @@ import io import json +import sys + from jsonrpc import JSONRPCResponseManager, Dispatcher import logging import threading @@ -352,4 +354,11 @@ def _send_document_update( logger.debug("Registering callable %s", callable_id) dispatcher[callable_id] = wrap_callable(callable) self._dispatcher = dispatcher - self._connection.on_data(payload.encode(), new_objects) + try: + self._connection.on_data(payload.encode(), new_objects) + except RuntimeError as e: + if "io.deephaven.plugin.type.ObjectCommunicationException" in str(e): + # can no longer send, don't need to raise exception but do need to exit + sys.exit() + else: + raise e From 925dcd33e18e7274326d47d712fb2a3b9d873dfc Mon Sep 17 00:00:00 2001 From: Joe Numainville Date: Mon, 22 Apr 2024 09:39:47 -0500 Subject: [PATCH 2/3] exit on close --- .../ui/object_types/ElementMessageStream.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/plugins/ui/src/deephaven/ui/object_types/ElementMessageStream.py b/plugins/ui/src/deephaven/ui/object_types/ElementMessageStream.py index 474b16ad1..9e3408db1 100644 --- a/plugins/ui/src/deephaven/ui/object_types/ElementMessageStream.py +++ b/plugins/ui/src/deephaven/ui/object_types/ElementMessageStream.py @@ -121,6 +121,11 @@ class ElementMessageStream(MessageStream): Captured ExecutionContext for this stream, to wrap all user code. """ + _is_closed: bool + """ + Whether or not the stream is closed. If closed, no more messages can be sent, and this component should exit. + """ + def __init__(self, element: Element, connection: MessageStream): """ Create a new ElementMessageStream. Renders the element in a render context, and sends the rendered result to the @@ -144,6 +149,7 @@ def __init__(self, element: Element, connection: MessageStream): self._is_dirty = False self._render_state = _RenderState.IDLE self._exec_context = get_exec_ctx() + self._is_closed = False def _render(self) -> None: logger.debug("ElementMessageStream._render") @@ -242,7 +248,7 @@ def start(self) -> None: self._connection.on_data(b"", []) def on_close(self) -> None: - pass + self._is_closed = True def on_data(self, payload: bytes, references: list[Any]) -> None: """ @@ -354,11 +360,6 @@ def _send_document_update( logger.debug("Registering callable %s", callable_id) dispatcher[callable_id] = wrap_callable(callable) self._dispatcher = dispatcher - try: - self._connection.on_data(payload.encode(), new_objects) - except RuntimeError as e: - if "io.deephaven.plugin.type.ObjectCommunicationException" in str(e): - # can no longer send, don't need to raise exception but do need to exit - sys.exit() - else: - raise e + if self._is_closed: + sys.exit() + self._connection.on_data(payload.encode(), new_objects) From 5e2e01b7756d49d2a822d5451758babdbe1fbdec Mon Sep 17 00:00:00 2001 From: Joe Numainville Date: Fri, 3 May 2024 10:10:17 -0500 Subject: [PATCH 3/3] comments --- .../ui/src/deephaven/ui/object_types/ElementMessageStream.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/ui/src/deephaven/ui/object_types/ElementMessageStream.py b/plugins/ui/src/deephaven/ui/object_types/ElementMessageStream.py index 9e3408db1..873bb6e6f 100644 --- a/plugins/ui/src/deephaven/ui/object_types/ElementMessageStream.py +++ b/plugins/ui/src/deephaven/ui/object_types/ElementMessageStream.py @@ -361,5 +361,8 @@ def _send_document_update( dispatcher[callable_id] = wrap_callable(callable) self._dispatcher = dispatcher if self._is_closed: + # The connection is closed, so this component will not update anymore + # delete the context so the objects in the collected scope are released + del self._context sys.exit() self._connection.on_data(payload.encode(), new_objects)