Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some ipywidgets interactions cause subsequent cells to hang when using the raw kernel #13971

Closed
1 of 2 tasks
jakobhansen-blai opened this issue Jul 24, 2023 · 6 comments · Fixed by #14867
Closed
1 of 2 tasks
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster ipywidgets Rendering, loading, saving, anything to do with IPyWidgets zmq Issues related to zmq

Comments

@jakobhansen-blai
Copy link

Applies To

  • Notebooks (.ipynb files)
  • Interactive Window and/or Cell Scripts (.py files with #%% markers)

What happened?

I have found this happening most consistently with bqplot interactions.

Create a plot with a brushable selection, e.g.:

import numpy as np
import bqplot as bq

x = np.linspace(-10, 10, 200)
y = np.sin(x)

x_sc = bq.LinearScale()
y_sc = bq.LinearScale()
line = bq.Lines(
    x=x,
    y=y,
    scales={"x": x_sc, "y": y_sc},
)
ax_x = bq.Axis(scale=x_sc)
ax_y = bq.Axis(scale=y_sc)
brushintsel = bq.interacts.BrushIntervalSelector(scale=x_sc, marks=[line])
fig = bq.Figure(
            marks=[line],
            axes=[ax_x, ax_y],
            interaction=brushintsel,
        )
display(fig)

The interaction with the plot using the brush selector behaves as expected, but after making a selection, trying to run any new cell simply hangs, with VSCode indicating that the cell is waiting to be executed. If no selection has been made, cells execute normally, but once any selection has been made, the only recourse seems to be restarting the kernel. The plot remains responsive throughout, however.

I have seen similar but temporary hangs when a widget runs a long task in the UI thread on instantiation, so perhaps something similar is going on here?

Setting "jupyter.disableZMQSupport": true (which I believe moves the backend to the Jupyter server rather than the raw kernel) seems to resolve the problem. I previously submitted this as an issue in bqplot (bqplot/bqplot#1618) but on discovering this workaround I thought it was probably better submitted here.

VS Code Version

1.80.1

Jupyter Extension Version

2023.6.1101941928

Jupyter logs

08:08:02.993 [debug] start the kernel, options.disableUI=false for ~/bqplot/brushintsel.ipynb
08:08:02.994 [debug] Execution Request Sent to Kernel for cell 0
08:08:03.027 [debug] Start cell 0 execution @ 1690211283023 (clear output)
08:08:03.028 [info] Kernel acknowledged execution of cell 0 @ 1690211283023
08:08:03.361 [info] End cell 0 execution @ 1690211283359, started @ 1690211283023, elapsed time = 0.336s
08:08:03.361 [debug] Cell 0 executed with state Success
08:08:04.745 [info] Handle Execution of Cells 1 for ~/bqplot/brushintsel.ipynb
08:08:04.746 [debug] start the kernel, options.disableUI=false for ~/bqplot/brushintsel.ipynb
08:08:04.747 [debug] Execution Request Sent to Kernel for cell 1
08:08:04.812 [debug] Start cell 1 execution @ 1690211284801 (clear output)
08:08:04.812 [info] Kernel acknowledged execution of cell 1 @ 1690211284801
08:08:04.846 [info] End cell 1 execution @ 1690211284833, started @ 1690211284801, elapsed time = 0.032s
08:08:04.847 [debug] Cell 1 executed with state Success
08:08:04.867 [debug] Widget Message: WidgetManager: Loading class LinearScaleModel:bqscales:^0.3
08:08:04.889 [debug] Widget Message: WidgetManager: Loading class LinearScaleModel:bqscales:^0.3
08:08:04.893 [debug] Widget Message: WidgetManager: Loading class LinesModel:bqplot:^0.6.0-alpha.0
08:08:04.894 [debug] Widget Message: WidgetManager: Loading class AxisModel:bqplot:^0.6.0-alpha.0
08:08:04.894 [debug] Widget Message: WidgetManager: Loading class AxisModel:bqplot:^0.6.0-alpha.0
08:08:04.894 [debug] Widget Message: WidgetManager: Loading class BrushIntervalSelectorModel:bqplot:^0.6.0-alpha.0
08:08:04.902 [debug] Widget Message: WidgetManager: Loading class LayoutModel:@jupyter-widgets/base:2.0.0
08:08:04.905 [debug] Widget Message: WidgetManager: Loading class LinearScaleModel:bqscales:^0.3
08:08:04.907 [debug] Widget Message: WidgetManager: Loading class LinearScaleModel:bqscales:^0.3
08:08:04.912 [debug] Widget Message: WidgetManager: Loading class FigureModel:bqplot:^0.6.0-alpha.0
08:08:04.923 [debug] Widget Message: Received display data message c433ac404957409c82515808b72dd363
08:08:05.163 [debug] Version of IPyWidgets 8 determined after 0s
08:08:05.184 [debug] Widget Message: Waiting for model to be available before rendering it c433ac404957409c82515808b72dd363
08:08:05.190 [debug] Widget Message: WidgetManager: Loading class Figure:bqplot:^0.6.0-alpha.0
08:08:05.192 [debug] Widget Message: WidgetManager: Loading class LayoutView:@jupyter-widgets/base:2.0.0
08:08:05.206 [debug] Widget Message: WidgetManager: Loading class LinearScale:bqscales:^0.3
08:08:05.219 [debug] Widget Message: WidgetManager: Loading class LinearScale:bqscales:^0.3
08:08:05.219 [debug] Widget Message: WidgetManager: Loading class Axis:bqplot:^0.6.0-alpha.0
08:08:05.219 [debug] Widget Message: WidgetManager: Loading class Axis:bqplot:^0.6.0-alpha.0
08:08:05.222 [debug] Widget Message: WidgetManager: Loading class LinearScale:bqscales:^0.3
08:08:05.226 [debug] Widget Message: WidgetManager: Loading class LinearScale:bqscales:^0.3
08:08:05.255 [debug] Widget Message: WidgetManager: Loading class Lines:bqplot:^0.6.0-alpha.0
08:08:05.258 [debug] Widget Message: WidgetManager: Loading class LinearScale:bqscales:^0.3
08:08:05.258 [debug] Widget Message: WidgetManager: Loading class LinearScale:bqscales:^0.3
08:08:05.270 [debug] Widget Message: WidgetManager: Loading class BrushIntervalSelector:bqplot:^0.6.0-alpha.0
08:08:05.274 [debug] Widget Message: WidgetManager: Loading class LinearScale:bqscales:^0.3
08:08:10.961 [info] Handle Execution of Cells 2 for ~/bqplot/brushintsel.ipynb
08:08:10.962 [debug] start the kernel, options.disableUI=false for ~/bqplot/brushintsel.ipynb
08:08:10.963 [debug] Execution Request Sent to Kernel for cell 2

Cell 0 is the imports, cell 1 creates and displays the figure, and cell 2 is the subsequent cell that never executes.



### Coding Language and Runtime Version

Python 3.10.12

### Language Extension Version (if applicable)

2023.12.0

### Anaconda Version (if applicable)

_No response_

### Running Jupyter locally or remotely?

Local
@jakobhansen-blai jakobhansen-blai added the bug Issue identified by VS Code Team member as probable bug label Jul 24, 2023
@amunger amunger assigned DonJayamanne and unassigned amunger Jul 24, 2023
@jakobhansen-blai jakobhansen-blai changed the title Some ipywidgets interactions cause UI thread to hang when using the raw kernel Some ipywidgets interactions cause subsequent cells to hang when using the raw kernel Jul 24, 2023
@DonJayamanne
Copy link
Contributor

Thanks for filing this issue, unfortunately I'm unable to replicate this at my end.
Please could you

  • Share a screen recording of how you interact with the graph
  • Also, plese could you enable verbose logging and share the full logs

Please could you enable logging as follows:

  • Open settings & go into Jupyter->Logging
  • Change the value to verbose
  • Reload VS Code,
  • Attempt to repro the issue & then copy the output from the Jupyter output panel.

@DonJayamanne DonJayamanne added notebook-execution zmq Issues related to zmq ipywidgets Rendering, loading, saving, anything to do with IPyWidgets info-needed Issue requires more information from poster labels Aug 6, 2023
@jakobhansen-blai
Copy link
Author

I changed the logging level to verbose but this didn't seem to add any new log entries. Not sure if I did something wrong there.

14:19:29.675 [debug] Restart kernel command handler for ~/bqplot/bqplot.ipynb
14:19:29.676 [debug] restart the kernel, options.disableUI=false for ~/bqplot/bqplot.ipynb
14:19:29.676 [info] Restart requested ~/bqplot/bqplot.ipynb
14:19:29.677 [debug] Cancel pending cells
14:19:29.677 [debug] Kernel Launcher. launch, Class name = Ky (started execution), Arg 1: "~/mambaforge/envs/bqplot/python.~/mambaforge/envs/bqplot/python.-m#ipykernel_launcher", Arg 2: 60000, Arg 3: "~/bqplot/bqplot.ipynb", Arg 4: "~/bqplot", Arg 5: ""
14:19:29.679 [info] Process Execution: ~/mambaforge/envs/bqplot/bin/python -c "import ipykernel; print(ipykernel.__version__); print("5dc3a68c-e34e-4080-9c3e-2a532b2ccb4d"); print(ipykernel.__file__)"
14:19:29.686 [debug] Launching kernel in kernelProcess.ts, Class name = Ly (started execution), Arg 1: "~/bqplot", Arg 2: ""
14:19:29.688 [debug] Kernel Env Variables for ~/.vscode/extensions/ms-toolsai.jupyter-2023.7.1002162226-darwin-arm64/temp/jupyter/kernels/pythonjvsc74a57bd014794c0e35fed875d3302a75138aa22ac5f4426b9c09a03b816b62d36ceec8ec/kernel.json, PATH value is ~/mambaforge/envs/bqplot/bin:~/.docker/bin:~/.docker/bin:~/mambaforge/envs/bqplot/bin:~/mambaforge/condabin:~/bin:/usr/local/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin
14:19:29.690 [info] Process Execution: ~/mambaforge/envs/bqplot/bin/python -m ipykernel_launcher --ip=127.0.0.1 --stdin=9003 --control=9001 --hb=9000 --Session.signature_scheme="hmac-sha256" --Session.key=b"66b11f8c-8e1d-46e7-b83f-8f5c4d701ddc" --shell=9002 --transport="tcp" --iopub=9004 --f=~/Library/Jupyter/runtime/kernel-v2-89497Xp1rTTKnlSIL.json
    > cwd: ~/bqplot
14:19:29.690 [debug] Launching kernel in kernelProcess.ts, Class name = Ly, completed in 4ms, has a truthy return value, Arg 1: "~/bqplot", Arg 2: ""
14:19:29.828 [info] ipykernel version & path 6.24.0, ~/mambaforge/envs/bqplot/lib/python3.10/site-packages/ipykernel/__init__.py for ~/mambaforge/envs/bqplot/bin/python
14:19:30.019 [debug] KernelProcess output: NOTE: When using the `ipython kernel` entry point, Ctrl-C will not work.

To exit, you will have to explicitly quit this process, by either sending
"quit" from a client, or using Ctrl-\ in UNIX-like environments.

To read more about this, see https://github.com/ipython/ipython/issues/2049


To connect another client to this kernel, use:
    --existing kernel-v2-89497Xp1rTTKnlSIL.json

14:19:30.019 [debug] Kernel Output: To connect another client to this kernel, use: --existing kernel-v2-89497Xp1rTTKnlSIL.json

14:19:30.100 [debug] Kernel Launcher. launch, Class name = Ky, completed in 422ms, has a truthy return value, Arg 1: "~/mambaforge/envs/bqplot/python.~/mambaforge/envs/bqplot/python.-m#ipykernel_launcher", Arg 2: 60000, Arg 3: "~/bqplot/bqplot.ipynb", Arg 4: "~/bqplot", Arg 5: ""
14:19:30.101 [debug] Waiting for Raw Session to be ready in postStartRawSession
14:19:30.101 [debug] Waiting for Raw session to be ready, currently connected
14:19:30.101 [debug] Raw session connected
14:19:30.101 [debug] Waiting for Raw session to be ready for 30s
14:19:30.101 [debug] Waited for Raw session to be ready & got connected
14:19:30.101 [debug] Successfully waited for Raw Session to be ready in postStartRawSession
14:19:30.101 [debug] Kernel status before requesting kernel info and after ready is unknown
14:19:30.101 [debug] Sending request for kernelinfo
14:19:30.105 [debug] Got response for requestKernelInfo
14:19:30.105 [debug] Successfully compelted postStartRawSession
14:19:30.106 [info] Started Kernel bqplot (Python 3.10.12) (pid: 90160)
14:19:30.106 [info] Started new session b88eef29-c1e6-4edf-910f-d10bcc34f12c
14:19:30.106 [debug] New Session after restarting b88eef29-c1e6-4edf-910f-d10bcc34f12c
14:19:30.106 [info] Shutdown old session 16300b13-8e34-43bc-bb5c-141cb01823e2
14:19:30.106 [debug] shutdownSession 16300b13-8e34-43bc-bb5c-141cb01823e2, .jvsc74a57bd014794c0e35fed875d3302a75138aa22ac5f4426b9c09a03b816b62d36ceec8ec.~/mambaforge/envs/bqplot/python.~/mambaforge/envs/bqplot/python.-m#ipykernel_launcher - start
14:19:30.106 [debug] Session can be shutdown .jvsc74a57bd014794c0e35fed875d3302a75138aa22ac5f4426b9c09a03b816b62d36ceec8ec.~/mambaforge/envs/bqplot/python.~/mambaforge/envs/bqplot/python.-m#ipykernel_launcher
14:19:30.106 [info] Dispose Kernel process 90141.
14:19:30.108 [debug] Begin sendTelemetryForPythonKernelExecutable
14:19:30.108 [debug] Executing silently Code (idle) = import sys as _VSCODE_sys\nprint(_VSCODE_sys.executable); del _VSCODE_sys
14:19:30.110 [debug] Widget Message: Received IPyWidgetMessages.IPyWidgets_onRestartKernel
14:19:30.111 [debug] Widget Message: Received IPyWidgets_kernelOptions in ScriptManager
14:19:30.113 [debug] Widget Message: Received IPyWidgetMessages.IPyWidgets_kernelOptions
14:19:30.114 [debug] IPyWidgetMessageDispatcher.initialize
14:19:30.114 [debug] IPyWidgetMessageDispatcher.initialize
14:19:30.122 [debug] Executing silently Code (completed) = import sys as _VSCODE_sys\nprint(_VSCODE_sys.executable); del _VSCODE_sys with 1 output(s)
14:19:30.123 [debug] End sendTelemetryForPythonKernelExecutable
14:19:30.123 [debug] Started running kernel initialization for ~/bqplot/bqplot.ipynb
14:19:30.123 [debug] Executing silently Code (idle) = try:\nimport ipywidgets as _VSCODE_ipywidgets\nprint("e976ee50-99ed-4aba-9b6b-9dcd5634d07d:IPy
14:19:30.127 [debug] Disposed Kernel process 90141.
14:19:30.127 [debug] shutdownSession 16300b13-8e34-43bc-bb5c-141cb01823e2, .jvsc74a57bd014794c0e35fed875d3302a75138aa22ac5f4426b9c09a03b816b62d36ceec8ec.~/mambaforge/envs/bqplot/python.~/mambaforge/envs/bqplot/python.-m#ipykernel_launcher - shutdown complete
14:19:30.130 [debug] KernelProcess Exited, Exit Code - undefined
14:19:30.160 [debug] Executing silently Code (completed) = try:\nimport ipywidgets as _VSCODE_ipywidgets\nprint("e976ee50-99ed-4aba-9b6b-9dcd5634d07d:IPy with 1 output(s)
14:19:30.160 [debug] Determined IPyWidgets Version as 8 and event fired
14:19:30.160 [debug] Executing silently Code (idle) = import os as _VSCODE_os\nimport sys as _VSCODE_sys\n%cd "/~/bqplot"\nif _VSCODE_os.get
14:19:30.167 [debug] Executing silently Code (completed) = import os as _VSCODE_os\nimport sys as _VSCODE_sys\n%cd "/~/bqplot"\nif _VSCODE_os.get with 1 output(s)
14:19:30.167 [debug] Requesting Kernel info
14:19:30.167 [debug] Got Kernel info
14:19:30.167 [debug] End running kernel initialization, now waiting for idle
14:19:30.167 [debug] Waiting for 60000ms idle on (kernel): b88eef29-c1e6-4edf-910f-d10bcc34f12c -> idle
14:19:30.167 [debug] Finished waiting for idle on (kernel): b88eef29-c1e6-4edf-910f-d10bcc34f12c -> idle
14:19:30.167 [debug] End running kernel initialization, session is idle
14:19:30.167 [debug] Registering commtarget jupyter.widget
14:19:46.965 [info] Handle Execution of Cells 0 for ~/bqplot/bqplot.ipynb
14:19:46.966 [debug] start the kernel, options.disableUI=false for ~/bqplot/bqplot.ipynb
14:19:46.967 [debug] Execution Request Sent to Kernel for cell 0
14:19:47.003 [debug] Start cell 0 execution @ 1691529586994 (clear output)
14:19:47.004 [info] Kernel acknowledged execution of cell 0 @ 1691529586994
14:19:47.424 [info] End cell 0 execution @ 1691529587421, started @ 1691529586994, elapsed time = 0.427s
14:19:47.424 [debug] Cell 0 executed with state Success
14:19:47.424 [debug] Widget Message: WidgetManager: Loading class LinearScaleModel:bqscales:^0.3
14:19:47.446 [debug] Widget Message: WidgetManager: Loading class LinearScaleModel:bqscales:^0.3
14:19:47.447 [debug] Widget Message: WidgetManager: Loading class LinesModel:bqplot:^0.6.0-alpha.0
14:19:47.452 [debug] Widget Message: WidgetManager: Loading class AxisModel:bqplot:^0.6.0-alpha.0
14:19:47.458 [debug] Widget Message: WidgetManager: Loading class AxisModel:bqplot:^0.6.0-alpha.0
14:19:47.463 [debug] Widget Message: WidgetManager: Loading class BrushIntervalSelectorModel:bqplot:^0.6.0-alpha.0
14:19:47.468 [debug] Widget Message: WidgetManager: Loading class LayoutModel:@jupyter-widgets/base:2.0.0
14:19:47.473 [debug] Widget Message: WidgetManager: Loading class LinearScaleModel:bqscales:^0.3
14:19:47.479 [debug] Widget Message: WidgetManager: Loading class LinearScaleModel:bqscales:^0.3
14:19:47.484 [debug] Widget Message: WidgetManager: Loading class FigureModel:bqplot:^0.6.0-alpha.0
14:19:48.359 [info] Handle Execution of Cells 1 for ~/bqplot/bqplot.ipynb
14:19:48.360 [debug] start the kernel, options.disableUI=false for ~/bqplot/bqplot.ipynb
14:19:48.361 [debug] Execution Request Sent to Kernel for cell 1
14:19:48.402 [debug] Start cell 1 execution @ 1691529588394 (clear output)
14:19:48.403 [info] Kernel acknowledged execution of cell 1 @ 1691529588394
14:19:48.405 [info] End cell 1 execution @ 1691529588403, started @ 1691529588394, elapsed time = 0.009s
14:19:48.405 [debug] Cell 1 executed with state Success
14:19:48.453 [debug] Widget Message: Received display data message 312d60ecba684713812ef2af40ca3b65
14:19:48.454 [debug] Version of IPyWidgets 8 determined after 0s
14:19:48.464 [debug] Widget Message: Waiting for model to be available before rendering it 312d60ecba684713812ef2af40ca3b65
14:19:48.466 [debug] Widget Message: WidgetManager: Loading class Figure:bqplot:^0.6.0-alpha.0
14:19:48.479 [debug] Widget Message: WidgetManager: Loading class LayoutView:@jupyter-widgets/base:2.0.0
14:19:48.496 [debug] Widget Message: WidgetManager: Loading class LinearScale:bqscales:^0.3
14:19:48.497 [debug] Widget Message: WidgetManager: Loading class LinearScale:bqscales:^0.3
14:19:48.498 [debug] Widget Message: WidgetManager: Loading class Axis:bqplot:^0.6.0-alpha.0
14:19:48.498 [debug] Widget Message: WidgetManager: Loading class Axis:bqplot:^0.6.0-alpha.0
14:19:48.498 [debug] Widget Message: WidgetManager: Loading class LinearScale:bqscales:^0.3
14:19:48.498 [debug] Widget Message: WidgetManager: Loading class LinearScale:bqscales:^0.3
14:19:48.513 [debug] Widget Message: WidgetManager: Loading class Lines:bqplot:^0.6.0-alpha.0
14:19:48.513 [debug] Widget Message: WidgetManager: Loading class LinearScale:bqscales:^0.3
14:19:48.513 [debug] Widget Message: WidgetManager: Loading class LinearScale:bqscales:^0.3
14:19:48.517 [debug] Widget Message: WidgetManager: Loading class BrushIntervalSelector:bqplot:^0.6.0-alpha.0
14:19:48.523 [debug] Widget Message: WidgetManager: Loading class LinearScale:bqscales:^0.3
14:19:52.531 [info] Handle Execution of Cells 2 for ~/bqplot/bqplot.ipynb
14:19:52.532 [debug] start the kernel, options.disableUI=false for ~/bqplot/bqplot.ipynb
14:19:52.533 [debug] Execution Request Sent to Kernel for cell 2
14:19:52.556 [debug] Start cell 2 execution @ 1691529592551 (clear output)
14:19:52.556 [info] Kernel acknowledged execution of cell 2 @ 1691529592551
14:19:52.558 [info] End cell 2 execution @ 1691529592556, started @ 1691529592551, elapsed time = 0.005s
14:19:52.558 [debug] Cell 2 executed with state Success
14:19:55.751 [info] Handle Execution of Cells 3 for ~/bqplot/bqplot.ipynb
14:19:55.752 [debug] start the kernel, options.disableUI=false for ~/bqplot/bqplot.ipynb
14:19:55.753 [debug] Execution Request Sent to Kernel for cell 3

Here's a video recording of the issue.

trimmed_bqplot_issue_720p.mov

@DonJayamanne
Copy link
Contributor

I'm so sorry for not getting back to you on this.
Are you still running into this issue?

@jakobhansen-blai
Copy link
Author

I do still have the issue when running with "jupyter.disableZMQSupport": false. One new note to report is that I seem to have the same issue in AWS Sagemaker, which is Jupyter Lab-based, but where the kernel runs on a separate VM from the Jupyter server process.

@DonJayamanne
Copy link
Contributor

I believe I have managed to identify the issue and fix this

Please could you

  • Download the attached file
  • Extract this file
  • Open VS Code and select the command Install from VSIX
  • Select the above extracted VSIX
  • When prompted to reload VS Code, please do so
  • Try to replicate the issue once again
    ms-toolsai-jupyter-insiders.vsix (1).zip

If this still does not fix it, please feel free to re-open this issue or feel free to create a new one or just ping me here

@DonJayamanne
Copy link
Contributor

Duplicate of #13469

@DonJayamanne DonJayamanne marked this as a duplicate of #13469 Dec 6, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster ipywidgets Rendering, loading, saving, anything to do with IPyWidgets zmq Issues related to zmq
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants