Hi, I have a question about best practices with notebook extensions and ipykernel comms.
I have an nbextension and a corresponding Python library which communicates with it via comms. When Jupyter loads the notebook page, it also loads the extension, which registers a comm.
Then when the user runs the Python library, the kernel sends a message which is picked up by the comm and activates the nbextension’s display logic.
However, there’s a race condition that happens when the user runs the Python library before the nbextension is loaded. In that case, the nbextension hasn’t registered the comm (since it hasn’t yet loaded). Once the kernel sends the message, I get this JS console error in Jupyter:
utils.js:930 Could not open comm -- Error: Class react.featuresapp not found in registry at utils.js:894 at new Promise (<anonymous>) at Object.load_class (utils.js:879) at CommManager.comm_open (comm.js:84) at i (jquery.min.js:2) at Kernel._handle_iopub_message (kernel.js:1223) at Kernel._finish_ws_message (kernel.js:1015) at kernel.js:1006
My overall question is: what’s the best-practice way to fix this? Some ideas:
- have the Python backend somehow detect that the comm failed and retry the message (this would still have an ugly console error though)
- maybe some way for the backend to register the extension before running it?
Also, minor suggestion: could we create a category on discourse.jupyter.org for ipykernel/nbextension issues? Or is there already a good forum for that?