We have recently upgraded from z2jh pre-1.0 to the latest version (jupyterlab 3.6.3). We use a mix of ipywidgets
and plotly
to visualise data for our clients, and we’re experiencing issues - mainly that the widgets don’t load properly, or our notebooks get ‘stuck’ during execution. I’m struggling to pin down the issue, but have managed to create a simple notebook that reproduces the problem after running it 5+ times:
import datetime
import ipywidgets as widgets # ipywidgets 8.0.6 but all 8.0.x versions exhibit the issue
import plotly.graph_objects as go # plotly 5.14.1
for i in range(20):
f = go.FigureWidget()
f.add_trace(go.Scatter(x=list(range(10_000)), y=list(range(10_000))))
w = widgets.VBox([
widgets.HTML(f"<b>Test {i} - {datetime.datetime.utcnow()}</b>"),
widgets.HBox([
widgets.Button(description=f"Button {i} a"),
widgets.Button(description=f"Button {i} b"),
widgets.Button(description=f"Button {i} c"),
widgets.Button(description=f"Button {i} d"),
widgets.Button(description=f"Button {i} e"),
widgets.Button(description=f"Button {i} f"),
]),
f,
])
t = widgets.Tab(titles=[f"{i}"], children=[w])
display(t)
…by the 5th or 6th run (restart kernel and run all cells) only a handful of the widgets are output, and then ~a minute or so later, the remainder are rendered.
In the logs for the singleuser notebook I can see errors, but I dont know if this is a smoking gun or a symptom of an underlying issue:
[I 2023-05-26 08:16:21.173 ServerApp] 200 GET /user/mksttrcmfe53e59e/api/sessions?1685088980909 (mksttrcmfe53e59e@10.1.122.143) 1.14ms
[I 2023-05-26 08:16:21.183 ServerApp] 200 GET /user/mksttrcmfe53e59e/api/kernels?1685088980910 (mksttrcmfe53e59e@10.1.122.143) 2.07ms
[E 2023-05-26 08:16:21.277 ServerApp] Uncaught exception in ZMQStream callback
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/zmq/eventloop/zmqstream.py", line 584, in _run_callback
f = callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/zmq/eventloop/zmqstream.py", line 308, in stream_callback
return callback(self, msg)
^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/jupyter_server/services/kernels/connection/channels.py", line 518, in handle_outgoing_message
self._on_zmq_reply(stream, msg)
File "/usr/local/lib/python3.11/site-packages/jupyter_server/services/kernels/connection/channels.py", line 575, in _on_zmq_reply
self.write_message(msg, binary=isinstance(msg, bytes))
File "/usr/local/lib/python3.11/site-packages/tornado/websocket.py", line 334, in write_message
return self.ws_connection.write_message(message, binary=binary)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/tornado/websocket.py", line 1081, in write_message
fut = self._write_frame(True, opcode, message, flags=flags)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/tornado/websocket.py", line 1056, in _write_frame
return self.stream.write(frame)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/tornado/iostream.py", line 539, in write
self._handle_write()
File "/usr/local/lib/python3.11/site-packages/tornado/iostream.py", line 1462, in _handle_write
super()._handle_write()
File "/usr/local/lib/python3.11/site-packages/tornado/iostream.py", line 965, in _handle_write
self._write_buffer.advance(num_bytes)
File "/usr/local/lib/python3.11/site-packages/tornado/iostream.py", line 182, in advance
assert 0 < size <= self._size
^^^^^^^^^^^^^^^^^^^^^^
AssertionError
[E 2023-05-26 08:16:21.278 ServerApp] Uncaught exception in zmqstream callback
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/zmq/eventloop/zmqstream.py", line 634, in _handle_events
self._handle_recv()
File "/usr/local/lib/python3.11/site-packages/zmq/eventloop/zmqstream.py", line 663, in _handle_recv
self._run_callback(callback, msg)
File "/usr/local/lib/python3.11/site-packages/zmq/eventloop/zmqstream.py", line 584, in _run_callback
f = callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/zmq/eventloop/zmqstream.py", line 308, in stream_callback
return callback(self, msg)
^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/jupyter_server/services/kernels/connection/channels.py", line 518, in handle_outgoing_message
self._on_zmq_reply(stream, msg)
File "/usr/local/lib/python3.11/site-packages/jupyter_server/services/kernels/connection/channels.py", line 575, in _on_zmq_reply
self.write_message(msg, binary=isinstance(msg, bytes))
File "/usr/local/lib/python3.11/site-packages/tornado/websocket.py", line 334, in write_message
return self.ws_connection.write_message(message, binary=binary)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/tornado/websocket.py", line 1081, in write_message
fut = self._write_frame(True, opcode, message, flags=flags)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/tornado/websocket.py", line 1056, in _write_frame
return self.stream.write(frame)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/tornado/iostream.py", line 539, in write
self._handle_write()
File "/usr/local/lib/python3.11/site-packages/tornado/iostream.py", line 1462, in _handle_write
super()._handle_write()
File "/usr/local/lib/python3.11/site-packages/tornado/iostream.py", line 965, in _handle_write
self._write_buffer.advance(num_bytes)
File "/usr/local/lib/python3.11/site-packages/tornado/iostream.py", line 182, in advance
assert 0 < size <= self._size
^^^^^^^^^^^^^^^^^^^^^^
AssertionError
[E 2023-05-26 08:16:21.278 ServerApp] Exception in callback functools.partial(<function ZMQStream._update_handler.<locals>.<lambda> at 0x7f1794433880>)
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/tornado/ioloop.py", line 738, in _run_callback
ret = callback()
^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/zmq/eventloop/zmqstream.py", line 718, in <lambda>
self.io_loop.add_callback(lambda: self._handle_events(self.socket, 0))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/zmq/eventloop/zmqstream.py", line 634, in _handle_events
self._handle_recv()
File "/usr/local/lib/python3.11/site-packages/zmq/eventloop/zmqstream.py", line 663, in _handle_recv
self._run_callback(callback, msg)
File "/usr/local/lib/python3.11/site-packages/zmq/eventloop/zmqstream.py", line 584, in _run_callback
f = callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/zmq/eventloop/zmqstream.py", line 308, in stream_callback
return callback(self, msg)
^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/jupyter_server/services/kernels/connection/channels.py", line 518, in handle_outgoing_message
self._on_zmq_reply(stream, msg)
File "/usr/local/lib/python3.11/site-packages/jupyter_server/services/kernels/connection/channels.py", line 575, in _on_zmq_reply
self.write_message(msg, binary=isinstance(msg, bytes))
File "/usr/local/lib/python3.11/site-packages/tornado/websocket.py", line 334, in write_message
return self.ws_connection.write_message(message, binary=binary)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/tornado/websocket.py", line 1081, in write_message
fut = self._write_frame(True, opcode, message, flags=flags)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/tornado/websocket.py", line 1056, in _write_frame
return self.stream.write(frame)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/tornado/iostream.py", line 539, in write
self._handle_write()
File "/usr/local/lib/python3.11/site-packages/tornado/iostream.py", line 1462, in _handle_write
super()._handle_write()
File "/usr/local/lib/python3.11/site-packages/tornado/iostream.py", line 965, in _handle_write
self._write_buffer.advance(num_bytes)
File "/usr/local/lib/python3.11/site-packages/tornado/iostream.py", line 182, in advance
assert 0 < size <= self._size
^^^^^^^^^^^^^^^^^^^^^^
AssertionError
[I 2023-05-26 08:17:21.214 ServerApp] Starting buffering for 5cbd7296-7b4d-47e4-b293-236ee1fdf426:12f99ae3-390c-41ac-9d82-105bf7540efc
[I 2023-05-26 08:17:21.427 ServerApp] 101 GET /user/mksttrcmfe53e59e/api/kernels/5cbd7296-7b4d-47e4-b293-236ee1fdf426/channels?session_id=12f99ae3-390c-41ac-9d82-105bf7540efc (mksttrcmfe53e59e@10.1.122.143) 1.47ms
[I 2023-05-26 08:17:21.427 ServerApp] Connecting to kernel 5cbd7296-7b4d-47e4-b293-236ee1fdf426.
[I 2023-05-26 08:17:21.427 ServerApp] Restoring connection for 5cbd7296-7b4d-47e4-b293-236ee1fdf426:12f99ae3-390c-41ac-9d82-105bf7540efc
[I 2023-05-26 08:17:21.462 ServerApp] Replaying 48 buffered messages
[I 2023-05-26 08:17:27.152 ServerApp] 101 GET /user/mksttrcmfe53e59e/api/events/subscribe?token=[secret] (mksttrcmfe53e59e@10.1.122.143) 0.74ms
[I 2023-05-26 08:17:35.935 ServerApp] 200 GET /user/mksttrcmfe53e59e/api/kernels?1685089055884 (mksttrcmfe53e59e@10.1.122.143) 1.12ms
It’s almost as if the code gets executed before the user has connected to the restarted kernel, or are some messages sent on the ‘previous’ kernel connection before it’s restarted, and it takes 60 seconds for something to reconnect?
If anyone can shed some light on either the issue, or how to troubleshoot the issue, that would be great. We don’t see the issue in production where we are running old versions (like 2+ years old) of everything.
Edit: Looking at the logs a bit more, it seems that if left idle, the kernel will continuously disconnect/reconnect every 60 (63?) seconds. I don’t know why this is happening, but am wondering if this is the source of the problem:
[I 2023-05-26 10:13:49.460 ServerApp] Connecting to kernel 85e599ad-4a18-405f-88cc-636913470181.
[I 2023-05-26 10:13:49.461 ServerApp] Restoring connection for 85e599ad-4a18-405f-88cc-636913470181:4221ff9f-edc2-40de-ac1b-797f697a02e1
[I 2023-05-26 10:14:52.532 ServerApp] Starting buffering for 85e599ad-4a18-405f-88cc-636913470181:4221ff9f-edc2-40de-ac1b-797f697a02e1
[I 2023-05-26 10:14:52.744 ServerApp] Connecting to kernel 85e599ad-4a18-405f-88cc-636913470181.
[I 2023-05-26 10:14:52.744 ServerApp] Restoring connection for 85e599ad-4a18-405f-88cc-636913470181:4221ff9f-edc2-40de-ac1b-797f697a02e1
[I 2023-05-26 10:15:55.214 ServerApp] Connecting to kernel 85e599ad-4a18-405f-88cc-636913470181.
[I 2023-05-26 10:15:55.214 ServerApp] Restoring connection for 85e599ad-4a18-405f-88cc-636913470181:4221ff9f-edc2-40de-ac1b-797f697a02e1
[I 2023-05-26 10:16:57.416 ServerApp] Connecting to kernel 85e599ad-4a18-405f-88cc-636913470181.
[I 2023-05-26 10:16:57.417 ServerApp] Restoring connection for 85e599ad-4a18-405f-88cc-636913470181:4221ff9f-edc2-40de-ac1b-797f697a02e1