From 25e24d7dfdf3086f157becb4001c97b3212ecbcb Mon Sep 17 00:00:00 2001 From: Mike Bender Date: Wed, 27 Dec 2023 20:38:18 -0500 Subject: [PATCH] fix: Incompatibility with older versions of Jupyter - We're accessing a private _context property, wrap it in a try/catch and just warn if there's an error - Tested against notebook 6.5.6 ```sh pip install deephaven-server notebook==6.5.6 jupyterlab pip install -e ".[test, examples]" jupyter notebook ``` Then running in the Jupyter notebook: ``` from deephaven_server import Server s = Server(jvm_args=["-Dauthentication.psk=iris"]) s.start() from deephaven import empty_table from deephaven_ipywidgets import DeephavenWidget t = empty_table(1000).update("x=i") display(DeephavenWidget(t)) ``` --- src/widget.ts | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/widget.ts b/src/widget.ts index fae65cc..0385a27 100644 --- a/src/widget.ts +++ b/src/widget.ts @@ -63,24 +63,32 @@ export class DeephavenView extends DOMWidgetView { constructor(options: Backbone.ViewOptions) { super(options); + this.initKernelListeners(); + } + + initKernelListeners(): void { this.model.on( 'change:kernel_active', () => this.onDisconnect('exiting'), this ); - // This uses the private _context property, but it's the only way to get - // the session context. These context listeners are used to listen to - // kernel events. See this file for examples within jupyter kernel: - // https://github.com/jupyter-widgets/ipywidgets/blob/47058a373d2c2b3acf101677b2745e14b76dd74b/python/jupyterlab_widgets/src/manager.ts#L427 - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - // eslint-disable-next-line no-underscore-dangle - this.context = this.model.widget_manager._context; - this.context.sessionContext.statusChanged.connect( - this.onRestartOrTerminate, - this - ); + try { + // This uses the private _context property, but it's the only way to get + // the session context. These context listeners are used to listen to + // kernel events. See this file for examples within jupyter kernel: + // https://github.com/jupyter-widgets/ipywidgets/blob/47058a373d2c2b3acf101677b2745e14b76dd74b/python/jupyterlab_widgets/src/manager.ts#L427 + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + // eslint-disable-next-line no-underscore-dangle + this.context = this.model.widget_manager._context; + this.context.sessionContext.statusChanged.connect( + this.onRestartOrTerminate, + this + ); + } catch (e) { + log.warn('Failed to add kernel listeners', e); + } } sendAuthenticationResponse = (