Skip to content

Commit

Permalink
fix: Incompatibility with older versions of Jupyter
Browse files Browse the repository at this point in the history
- 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))
```
  • Loading branch information
mofojed committed Dec 28, 2023
1 parent 3a727c2 commit 25e24d7
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions src/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,32 @@ export class DeephavenView extends DOMWidgetView {
constructor(options: Backbone.ViewOptions<DeephavenModel>) {
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 = (
Expand Down

0 comments on commit 25e24d7

Please sign in to comment.