vscode-jupyter: `aggdraw.Draw` causes kernel to die, not in web interface, only in VS Code

Applies To

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

What happened?

After installing aggdraw in a conda environment via conda install -c conda-forge aggdraw I had the following issue:

I ran this cell

import aggdraw
# print('aggdraw version', aggdraw.__version__) # = 1.3.16
d = aggdraw.Draw("RGB", (100, 100), (0,0,0))

and after a very short time the kernel died. Same happens when I use agg_draw = aggdraw.Draw(pil_image).

The result was The Kernel crashed while executing code in the the current cell or a previous cell. Please review the code in the cell(s) to identify a possible cause of the failure. Click [here](https://aka.ms/vscodeJupyterKernelCrash) for more info. View Jupyter [log](command:jupyter.viewOutput) for further details.

It is possible to use the cell for complex drawing and a following cell to print some text even after using time.sleep(5), but sooner or later the message of the crashed kernel comes up and then it’s no longer possible to re-run the notebook.

Clicking “Restart” hangs up the restarting task, it stays at “Restarting Kernel: Python 3.11”. I then need to remove the kernel via the web ui because the small “Restarting Kernel” notification offers no way to abort this.

VS Code is running locally on Windows (192.168.30.41), the Jupyter instance is running on a Linux server (192.168.30.25), to which VS Code is also connected via the SSH Extension (Visual Studio Code Remote).

miniconda got installed around 3 days ago.

VS Code Version

Version: 1.81.1 (user setup) Commit: 6c3e3dba23e8fadc360aed75ce363ba185c49794 Date: 2023-08-09T22:22:42.175Z Electron: 22.3.18 ElectronBuildId: 22689846 Chromium: 108.0.5359.215 Node.js: 16.17.1 V8: 10.8.168.25-electron.0 OS: Windows_NT x64 10.0.22621

Jupyter Extension Version

v2023.7.1002162226

Jupyter logs

[D 2023-09-02 00:43:55.831 ServerApp] Accepting token-authenticated request from 192.168.30.41
[D 2023-09-02 00:43:55.832 ServerApp] 200 GET /api/sessions?1693608235866 (51f58065604841788378348310d01476@192.168.30.41) 1.12ms
[D 2023-09-02 00:43:55.832 ServerApp] Accepting token-authenticated request from 192.168.30.41
[D 2023-09-02 00:43:55.838 ServerApp] 200 GET /api/contents/notebooks/Mapping?content=1&1693608235866 (51f58065604841788378348310d01476@192.168.30.41) 7.19ms
[I 2023-09-02 00:43:56.189 ServerApp] AsyncIOLoopKernelRestarter: restarting kernel (1/5), keep random ports
[W 2023-09-02 00:43:56.189 ServerApp] kernel c74a501a-185c-4460-a98b-856f5d262c4c restarted
[D 2023-09-02 00:43:56.192 ServerApp] Websocket closed c74a501a-185c-4460-a98b-856f5d262c4c:7fb8392c-61ee-4454-a288-79098c81f89b
[I 2023-09-02 00:43:56.192 ServerApp] Starting buffering for c74a501a-185c-4460-a98b-856f5d262c4c:7fb8392c-61ee-4454-a288-79098c81f89b
[D 2023-09-02 00:43:56.192 ServerApp] Clearing buffer for c74a501a-185c-4460-a98b-856f5d262c4c
[D 2023-09-02 00:43:56.195 ServerApp] Accepting token-authenticated request from 192.168.30.25
[D 2023-09-02 00:43:56.196 ServerApp] Generating new user for token-authenticated request: 2c09be001d1c46848ac775834800c1e4
[D 2023-09-02 00:43:56.201 ServerApp] Starting kernel: ['/home/user/miniconda3/envs/gdal/bin/python3', '-m', 'ipykernel_launcher', '-f', '/home/user/.local/share/jupyter/runtime/kernel-c74a501a-185c-4460-a98b-856f5d262c4c.json']
[D 2023-09-02 00:43:56.204 ServerApp] Connecting to: tcp://127.0.0.1:43485
[D 2023-09-02 00:43:56.205 ServerApp] 101 GET /api/kernels/c74a501a-185c-4460-a98b-856f5d262c4c/channels?session_id=7fb8392c-61ee-4454-a288-79098c81f89b&token=[secret] (2c09be001d1c46848ac775834800c1e4@192.168.30.25) 10.12ms
[D 2023-09-02 00:43:56.206 ServerApp] Opening websocket /api/kernels/c74a501a-185c-4460-a98b-856f5d262c4c/channels
[I 2023-09-02 00:43:56.206 ServerApp] Connecting to kernel c74a501a-185c-4460-a98b-856f5d262c4c.
[D 2023-09-02 00:43:56.206 ServerApp] Getting buffer for c74a501a-185c-4460-a98b-856f5d262c4c
[I 2023-09-02 00:43:56.206 ServerApp] Restoring connection for c74a501a-185c-4460-a98b-856f5d262c4c:7fb8392c-61ee-4454-a288-79098c81f89b
[D 2023-09-02 00:43:56.206 ServerApp] Nudge: not nudging busy kernel c74a501a-185c-4460-a98b-856f5d262c4c
0.00s - Debugger warning: It seems that frozen modules are being used, which may
0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
0.00s - to python to disable frozen modules.
0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.
[D 2023-09-02 00:43:56.562 ServerApp] activity on c74a501a-185c-4460-a98b-856f5d262c4c: status (busy)
[D 2023-09-02 00:43:56.563 ServerApp] activity on c74a501a-185c-4460-a98b-856f5d262c4c: status (idle)
[D 2023-09-02 00:43:56.569 ServerApp] activity on c74a501a-185c-4460-a98b-856f5d262c4c: status (busy)
[D 2023-09-02 00:43:56.576 ServerApp] activity on c74a501a-185c-4460-a98b-856f5d262c4c: execute_input
[D 2023-09-02 00:43:56.580 ServerApp] activity on c74a501a-185c-4460-a98b-856f5d262c4c: stream
[D 2023-09-02 00:43:56.581 ServerApp] activity on c74a501a-185c-4460-a98b-856f5d262c4c: status (idle)
[D 2023-09-02 00:44:05.741 ServerApp] Accepting token-authenticated request from 192.168.20.25
[D 2023-09-02 00:44:05.741 ServerApp] Generating new user for token-authenticated request: 0dd7402b8a7042068fe8ff0b45ed9bce
[D 2023-09-02 00:44:05.741 ServerApp] 200 GET /api/kernels?1693608245737 (0dd7402b8a7042068fe8ff0b45ed9bce@192.168.20.25) 1.27ms
[D 2023-09-02 00:44:05.742 ServerApp] Accepting token-authenticated request from 192.168.20.25

Coding Language and Runtime Version

Python 3.11.4 (main, Jul 5 2023, 13:45:01) [GCC 11.2.0] on linux

Language Extension Version (if applicable)

Python v2023.14.0

Anaconda Version (if applicable)

conda 23.5.2 (miniconda latest, Python 3.11)

Running Jupyter locally or remotely?

Remote

About this issue

  • Original URL
  • State: open
  • Created 10 months ago
  • Comments: 15 (9 by maintainers)

Most upvoted comments

@DonJayamanne this is still happening ( extension version: v2023.10.1100000000 ):

# clearing all logs and restarting the kernel
22:53:03.023 [debug] Restart kernel command handler for ~/python/jupyter/notebooks/Mapping/Aggdraw-Test.ipynb
22:53:03.023 [debug] restart the kernel, options.disableUI=false for ~/python/jupyter/notebooks/Mapping/Aggdraw-Test.ipynb
22:53:03.023 [info] Restart requested ~/python/jupyter/notebooks/Mapping/Aggdraw-Test.ipynb
22:53:03.024 [debug] Cancel pending cells
22:53:03.160 [debug] Updating preferred kernel for remote notebook 6e451405-1639-472a-9b44-d7cd8d3a08ca
22:53:03.160 [info] Restarted 6e451405-1639-472a-9b44-d7cd8d3a08ca
22:53:03.160 [debug] Storing Preferred remote kernel for ~/python/jupyter/notebooks/Mapping/Aggdraw-Test.ipynb is 6e451405-1639-472a-9b44-d7cd8d3a08ca
22:53:03.160 [debug] Started running kernel initialization for ~/python/jupyter/notebooks/Mapping/Aggdraw-Test.ipynb
22:53:03.160 [debug] Executing silently Code (unknown) = try:\nimport ipywidgets as _VSCODE_ipywidgets\nprint("e976ee50-99ed-4aba-9b6b-9dcd5634d07d:IPy
22:53:03.500 [debug] Executing silently Code (completed) = try:\nimport ipywidgets as _VSCODE_ipywidgets\nprint("e976ee50-99ed-4aba-9b6b-9dcd5634d07d:IPy with 0 output(s)
22:53:03.500 [debug] Determined IPyWidgets Version as undefined and event fired
22:53:03.501 [debug] Executing silently Code (idle) = __vsc_ipynb_file__ = "~/python/jupyter/notebooks/Mapping/Aggdraw-Test.ipynb"\n%config Complete
22:53:03.506 [debug] Executing silently Code (completed) = __vsc_ipynb_file__ = "~/python/jupyter/notebooks/Mapping/Aggdraw-Test.ipynb"\n%config Complete with 0 output(s)
22:53:03.506 [debug] Requesting Kernel info
22:53:03.507 [debug] Got Kernel info
22:53:03.507 [debug] End running kernel initialization, now waiting for idle
22:53:03.507 [debug] Waiting for 60000ms idle on (kernel): 6e451405-1639-472a-9b44-d7cd8d3a08ca -> idle
22:53:03.507 [debug] Finished waiting for idle on (kernel): 6e451405-1639-472a-9b44-d7cd8d3a08ca -> idle
22:53:03.507 [debug] End running kernel initialization, session is idle
22:53:03.507 [debug] Registering commtarget jupyter.widget
# performing a run-all
22:53:11.557 [info] Handle Execution of Cells 0 for ~/python/jupyter/notebooks/Mapping/Aggdraw-Test.ipynb
22:53:11.558 [debug] start the kernel, options.disableUI=false for ~/python/jupyter/notebooks/Mapping/Aggdraw-Test.ipynb
22:53:11.558 [debug] Execution Request Sent to Kernel for cell 0
22:53:11.568 [debug] Start cell 0 execution @ 1701985991568 (clear output)
22:53:11.568 [info] Kernel acknowledged execution of cell 0 @ 1701985991568
22:53:11.589 [info] End cell 0 execution @ 1701985991589, started @ 1701985991568, elapsed time = 0.021s
22:53:11.590 [debug] Cell 0 executed with state Success
22:53:11.671 [debug] Executing silently Code (idle) = def _VSCODE_getVariable(what_to_get, is_debugging, *args):\n# Query Jupyter server for the info a
22:53:12.146 [debug] Start cell 0 execution @ 1701985991589
22:53:12.147 [error] Jupyter Extension (Error in requestVariables, method:requestVariables): Error: Canceled future for execute_request message before replies were done
    at t.KernelShellFutureHandler.dispose (~/.vscode-server/extensions/ms-toolsai.jupyter-2023.10.1100000000-linux-x64/out/extension.node.js:2:32375)
    at ~/.vscode-server/extensions/ms-toolsai.jupyter-2023.10.1100000000-linux-x64/out/extension.node.js:2:26594
    at Map.forEach (<anonymous>)
    at y._clearKernelState (~/.vscode-server/extensions/ms-toolsai.jupyter-2023.10.1100000000-linux-x64/out/extension.node.js:2:26579)
    at ~/.vscode-server/extensions/ms-toolsai.jupyter-2023.10.1100000000-linux-x64/out/extension.node.js:2:29022
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
22:53:12.222 [info] End cell 0 execution @ undefined, started @ 1701985991589, elapsed time = -1701985991.589s
22:53:12.257 [debug] Executing silently Code (unknown) = def _VSCODE_getVariable(what_to_get, is_debugging, *args):\n# Query Jupyter server for the info a

This cell is the only one in the notebook:

import aggdraw
from PIL import Image, ImageDraw
 
print('aggdraw version', aggdraw.__version__)
# aggdraw version 1.3.12 -- on aiohttp
# aggdraw version 1.3.16 -- in conda

# WARN `USE_AGGDRAW = True` causes the kernel to crash 
USE_AGGDRAW = True

img = Image.new("RGB", (256, 256), "white")

if USE_AGGDRAW:
    agg_draw = aggdraw.Draw(img)
else:
    draw = ImageDraw.Draw(img)

# Diagonal line
p1 = (0,0)
p2 = (255,255)

if USE_AGGDRAW:
    pen = aggdraw.Pen(color=(255,0,0), width=10, opacity=127)
    agg_draw.line((p1[0], p1[1], p2[0], p2[1]), pen)
else:
    draw.line([p1, p2], fill="red", width=10)

if USE_AGGDRAW:
    agg_draw.flush()

display(img)

and outputs this result:

aggdraw version 1.3.16

[image correctly rendered]

The Kernel crashed while executing code in the the current cell or a previous cell. Please review the code in the cell(s) to identify a possible cause of the failure. Click [here](https://aka.ms/vscodeJupyterKernelCrash) for more info. View Jupyter [log](command:jupyter.viewOutput) for further details.

It still applies that if the “Variables”-panel is collapsed, then the Kernel doesn’t crash.

Turns out that running only the following cell no longer triggers a Kernel crash, so apparently now the behavior is different:

import aggdraw
# print('aggdraw version', aggdraw.__version__) # = 1.3.16
d = aggdraw.Draw("RGB", (100, 100), (0,0,0))

This small cell used to cause the problem as well.

I noticed that in the example cell which does cause a crash, the “Variables”-panel does not show any variables at all (“no variables defined”)

Regarding the last added information with the two cells: This works in a simple notebook, but not in a larger one. In any case, closing the variable view “fixes” the issue 100%.