microsoft / vscode-jupyter

VS Code Jupyter extension

Home Page:https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Running `Developer: Reload Window` with multiple notebooks open running remote kernels can result in them connecting to the same running kernel

andyscho opened this issue · comments

Applies To

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

Did not test it with Interactive Window, but would not be surprised if it reproduces there too.

What happened?

Running Developer: Reload Window with multiple notebooks open running remote kernels can result in them connecting to the same running kernel.

Steps to reproduce:

  1. Start a jupyter server to connect to.
  2. Open two different notebooks. I did not check to see if the name of the notebook matters in which kernel gets picked.
  3. Select a kernel in each of the two notebooks. They can be the same kernelspec, or different ones. I was able to reproduce in both cases.
  4. Make sure kernels are started/execute code on both.
  5. Run Developer: Reload Window. You might have to run this multiple times before observing the issue. In the video below, I run the reload window command two times before observing the issue.

Video of reproduction below:

reproduce-issue-2024-05-14.webm

VS Code Version

Version: 1.90.0-insider (Universal) Commit: bbc4ba1eff648ee542972589216f211b7a6a08f2 Date: 2024-05-14T05:49:42.658Z (21 hrs ago)

Jupyter Extension Version

v2024.4.2024042601 (pre-release)

Jupyter logs

Logs attached are after the most recent reload.

Visual Studio Code - Insiders (1.90.0-insider, undefined, desktop)
Jupyter Extension Version: 2024.4.2024042601.
Python Extension Version: 2024.7.11341012.
Pylance Extension Version: 2024.5.100.
Platform: darwin (arm64).
Workspace folder ~/pg/misc-python, Home = /Users/andy
23:28:14.112 [debug] Start refreshing Kernel Picker (1715743694112)
23:28:14.125 [debug] Preferred Remote kernel for ~/pg/misc-python/example copy.ipynb is 8fcde2d0-f813-4409-996c-3e8fda5e52c4
23:28:14.174 [debug] No controller, hence notebook communications cannot be initialized for editor ~/pg/misc-python/example copy.ipynb
23:28:14.174 [debug] Start refreshing Interpreter Kernel Picker
23:28:14.219 [debug] Preferred Remote kernel for ~/pg/misc-python/example.ipynb is 1a1a2219-30ac-45b0-8dc4-f62ae99a1ad0
23:28:14.232 [debug] Search for KernelSpecs in Interpreter /opt/homebrew/bin/python3
23:28:14.232 [debug] Search for KernelSpecs in Interpreter /usr/bin/python3
23:28:14.232 [debug] Search for KernelSpecs in Interpreter ~/pg/misc-python/.venv/bin/python
23:28:14.232 [debug] Search for KernelSpecs in Interpreter ~/pg/misc-python/env/bin/python
23:28:14.233 [debug] Get Custom Env Variables, Class name = qm, completed in 121ms, has a truthy return value, Arg 1: undefined, Arg 2: "RunPythonCode"
23:28:14.233 [debug] Jupyter Paths /kernels: 
23:28:14.234 [debug] Kernel Spec Root Paths, /usr/share/jupyter/kernels, /usr/local/share/jupyter/kernels, ~/Library/Jupyter/kernels
23:28:14.269 [debug] UniversalRemoteKernelFinder: Writing 2 remote kernel connection metadata to cache
23:28:14.457 [debug] Hiding default KernelSpec 'python3116jvsc74a57bd0b16c44b261b3989786f7b7830790d0ff27b626167bc732a7103db8a89067d8f2', /python for interpreter ~/pg/misc-python/.venv/bin/python (KernelSpec file ~/pg/misc-python/.venv/share/jupyter/kernels/python3/kernel.json)
23:28:14.458 [debug] Using notebook.selectKernel to force remote kernel for ~/pg/misc-python/example copy.ipynb to 8fcde2d0-f813-4409-996c-3e8fda5e52c4
23:28:14.458 [debug] Using notebook.selectKernel to force remote kernel for ~/pg/misc-python/example.ipynb to 1a1a2219-30ac-45b0-8dc4-f62ae99a1ad0
23:28:14.466 [debug] Hiding default KernelSpec 'python3116jvsc74a57bd06693c0e3f55cef1650de56e3bd6f23b757fc75978e136c1a813ff6c035531c79', /python for interpreter ~/pg/misc-python/env/bin/python (KernelSpec file ~/pg/misc-python/env/share/jupyter/kernels/python3/kernel.json)
23:28:14.467 [debug] Kernels for interpreter /Users/~/pg/misc-python/env/bin/python are .jvsc74a57bd06693c0e3f55cef1650de56e3bd6f23b757fc75978e136c1a813ff6c035531c79#kernel0./Users/~/pg/misc-python/env/python./Users/~/pg/misc-python/env/python.-m#ipykernel_launcher, .jvsc74a57bd06693c0e3f55cef1650de56e3bd6f23b757fc75978e136c1a813ff6c035531c79#kernel2./Users/~/pg/misc-python/env/python./Users/~/pg/misc-python/env/python.-m#ipykernel_launcher, .jvsc74a57bd06693c0e3f55cef1650de56e3bd6f23b757fc75978e136c1a813ff6c035531c79#kernel1./Users/~/pg/misc-python/env/python./Users/~/pg/misc-python/env/python.-m#ipykernel_launcher, .jvsc74a57bd06693c0e3f55cef1650de56e3bd6f23b757fc75978e136c1a813ff6c035531c79#kernel3./Users/~/pg/misc-python/env/python./Users/~/pg/misc-python/env/python.-m#ipykernel_launcher, .jvsc74a57bd06693c0e3f55cef1650de56e3bd6f23b757fc75978e136c1a813ff6c035531c79#kernel4./Users/~/pg/misc-python/env/python./Users/~/pg/misc-python/env/python.-m#ipykernel_launcher, .jvsc74a57bd06693c0e3f55cef1650de56e3bd6f23b757fc75978e136c1a813ff6c035531c79./Users/~/pg/misc-python/env/python./Users/~/pg/misc-python/env/python.-m#ipykernel_launcher
23:28:14.485 [debug] KernelProvider switched kernel to id = 1a1a2219-30ac-45b0-8dc4-f62ae99a1ad0
23:28:14.485 [debug] Controller selection change completed
23:28:14.485 [debug] KernelProvider switched kernel to id = 8fcde2d0-f813-4409-996c-3e8fda5e52c4
23:28:14.489 [debug] Registering commtarget jupyter.widget
23:28:14.490 [debug] Controller selection change completed
23:28:14.490 [debug] Disposing kernel associated with ~/pg/misc-python/example copy.ipynb, isClosed=false
23:28:14.490 [info] Dispose Kernel '~/pg/misc-python/example copy.ipynb' associated with '~/pg/misc-python/example copy.ipynb'
23:28:14.491 [debug] Kernel got disposed, hence there is no longer a kernel associated with ~/pg/misc-python/example copy.ipynb
23:28:14.491 [debug] KernelProvider switched kernel to id = 1a1a2219-30ac-45b0-8dc4-f62ae99a1ad0
23:28:14.491 [debug] Registering commtarget jupyter.widget
23:28:14.491 [debug] Controller selection change completed
23:28:14.502 [debug] Conda file is conda
23:28:14.510 [warn] Password for http://localhost:8289/ was invalid.
23:28:14.554 [debug] Disposing Jupyter Lab Helper
23:28:14.554 [debug] SessionManager - dispose contents manager
23:28:14.554 [debug] ShutdownSessionAndConnection - dispose session manager
23:28:14.554 [debug] Finished disposing Jupyter Lab Helper
23:28:14.554 [debug] UniversalRemoteKernelFinder: Writing 8 remote kernel connection metadata to cache
23:28:14.558 [debug] Disposing Jupyter Lab Helper
23:28:14.558 [debug] SessionManager - dispose contents manager
23:28:14.558 [debug] ShutdownSessionAndConnection - dispose session manager
23:28:14.558 [debug] Finished disposing Jupyter Lab Helper
23:28:14.558 [debug] UniversalRemoteKernelFinder: Writing 8 remote kernel connection metadata to cache
23:28:14.655 [debug] Refreshed Environments
23:28:15.660 [debug] End refreshing Kernel Picker (1715743694112)
23:28:16.482 [warn] Failed to switch remote kernel for ~/pg/misc-python/example copy.ipynb to 8fcde2d0-f813-4409-996c-3e8fda5e52c4
23:28:16.482 [warn] Failed to switch remote kernel for ~/pg/misc-python/example.ipynb to 1a1a2219-30ac-45b0-8dc4-f62ae99a1ad0
23:28:16.490 [debug] Start refreshing Kernel Picker (1715743696490)
23:28:16.509 [debug] Disposing Jupyter Lab Helper
23:28:16.509 [debug] SessionManager - dispose contents manager
23:28:16.509 [debug] ShutdownSessionAndConnection - dispose session manager
23:28:16.509 [debug] Finished disposing Jupyter Lab Helper
23:28:16.509 [debug] UniversalRemoteKernelFinder: Writing 8 remote kernel connection metadata to cache
23:28:16.562 [debug] End refreshing Kernel Picker (1715743696490)
23:28:18.213 [info] Handle Execution of Cells 1 for ~/pg/misc-python/example copy.ipynb
23:28:18.214 [debug] start the kernel, options.disableUI=false for ~/pg/misc-python/example copy.ipynb
23:28:18.216 [info] Starting Kernel connectToLiveRemoteKernel, 1a1a2219-30ac-45b0-8dc4-f62ae99a1ad0  for '~/pg/misc-python/example copy.ipynb' (disableUI=false)
23:28:18.225 [warn] Password for http://localhost:8289/ was invalid.
23:28:18.336 [info] Started session for kernel connectToLiveRemoteKernel:1a1a2219-30ac-45b0-8dc4-f62ae99a1ad0
23:28:18.336 [debug] Started running kernel initialization for ~/pg/misc-python/example copy.ipynb
23:28:18.337 [debug] Executing silently Code (idle) = try:\nimport ipywidgets as _VSCODE_ipywidgets\nprint("e976ee50-99ed-4aba-9b6b-9dcd5634d07d:IPy
23:28:18.337 [debug] Requesting Kernel info
23:28:18.337 [debug] Got Kernel info
23:28:18.337 [debug] Executing silently Code (idle) = def __VSCODE_inject_module():\ndef __VSCODE_call_function(function, callback, data=None):
23:28:18.338 [debug] Registering Kernel Completion Provider from kernel kernel1 (example.ipynb) for language python
23:28:18.338 [debug] Start refreshing Kernel Picker (1715743698338)
23:28:18.338 [debug] IPyWidgetScriptSource.initialize
23:28:18.340 [debug] Executing silently Code (idle) = import os as _VSCODE_os\nimport sys as _VSCODE_sys\nimport builtins as _VSCODE_builtins\nif _VSCODE_o
23:28:18.342 [debug] Cell Index:1 sent to kernel
23:28:18.345 [debug] Executing silently Code (completed) = try:\nimport ipywidgets as _VSCODE_ipywidgets\nprint("e976ee50-99ed-4aba-9b6b-9dcd5634d07d:IPy with 1 output(s)
23:28:18.345 [debug] Determined IPyWidgets Version as 8
23:28:18.345 [debug] Version of IPyWidgets 8 determined after 3.854s
23:28:18.349 [debug] Executing silently Code (idle) = # Copyright (c) Microsoft Corporation. All rights reserved.\n# Licensed under the MIT License.\n# Sou
23:28:18.353 [debug] Executing silently Code (completed) = def __VSCODE_inject_module():\ndef __VSCODE_call_function(function, callback, data=None): with 0 output(s)
23:28:18.360 [debug] Disposing Jupyter Lab Helper
23:28:18.360 [debug] SessionManager - dispose contents manager
23:28:18.360 [debug] ShutdownSessionAndConnection - dispose session manager
23:28:18.360 [debug] Finished disposing Jupyter Lab Helper
23:28:18.360 [debug] UniversalRemoteKernelFinder: Writing 8 remote kernel connection metadata to cache
23:28:18.361 [debug] Executing silently Code (completed) = import os as _VSCODE_os\nimport sys as _VSCODE_sys\nimport builtins as _VSCODE_builtins\nif _VSCODE_o with 1 output(s)
23:28:18.362 [debug] Start cell 1 execution @ 1715743698362 (clear output)
23:28:18.362 [debug] Kernel acknowledged execution of cell 1 @ 1715743698362
23:28:18.362 [debug] Remote Interpreter for Pylance for Notebook URI "~/pg/misc-python/example copy.ipynb" is ~/pg/misc-python/env/bin/python3.11
23:28:18.363 [info] Cell 1 completed in 0.001s (start: 1715743698362, end: 1715743698363)
23:28:18.364 [debug] Cell 1 executed successfully
23:28:18.369 [debug] Executing silently Code (completed) = # Copyright (c) Microsoft Corporation. All rights reserved.\n# Licensed under the MIT License.\n# Sou with 1 output(s)
23:28:18.369 [debug] Widget Outputs include, ['/jupyter-js-widgets/extension.js']

23:28:18.385 [debug] End refreshing Kernel Picker (1715743698338)
23:28:18.619 [debug] Executing silently Code (idle) = import os as _VSCODE_os\nimport sys as _VSCODE_sys\nimport builtins as _VSCODE_builtins\nif _VSCODE_o
23:28:18.625 [debug] Executing silently Code (completed) = import os as _VSCODE_os\nimport sys as _VSCODE_sys\nimport builtins as _VSCODE_builtins\nif _VSCODE_o with 1 output(s)
23:28:18.625 [debug] Remote Interpreter for Pylance for Notebook URI "~/pg/misc-python/example copy.ipynb" is ~/pg/misc-python/env/bin/python3.11
23:28:18.626 [debug] Executing silently Code (idle) = import os as _VSCODE_os\nimport sys as _VSCODE_sys\nimport builtins as _VSCODE_builtins\nif _VSCODE_o
23:28:18.631 [debug] Executing silently Code (completed) = import os as _VSCODE_os\nimport sys as _VSCODE_sys\nimport builtins as _VSCODE_builtins\nif _VSCODE_o with 1 output(s)
23:28:18.631 [debug] Remote Interpreter for Pylance for Notebook URI "~/pg/misc-python/example copy.ipynb" is ~/pg/misc-python/env/bin/python3.11
23:28:18.632 [debug] Executing silently Code (idle) = import os as _VSCODE_os\nimport sys as _VSCODE_sys\nimport builtins as _VSCODE_builtins\nif _VSCODE_o
23:28:18.637 [debug] Executing silently Code (completed) = import os as _VSCODE_os\nimport sys as _VSCODE_sys\nimport builtins as _VSCODE_builtins\nif _VSCODE_o with 1 output(s)
23:28:18.637 [debug] Remote Interpreter for Pylance for Notebook URI "~/pg/misc-python/example copy.ipynb" is ~/pg/misc-python/env/bin/python3.11
23:28:18.638 [debug] Executing silently Code (idle) = import os as _VSCODE_os\nimport sys as _VSCODE_sys\nimport builtins as _VSCODE_builtins\nif _VSCODE_o
23:28:18.642 [debug] Executing silently Code (completed) = import os as _VSCODE_os\nimport sys as _VSCODE_sys\nimport builtins as _VSCODE_builtins\nif _VSCODE_o with 1 output(s)
23:28:18.643 [debug] Remote Interpreter for Pylance for Notebook URI "~/pg/misc-python/example copy.ipynb" is ~/pg/misc-python/env/bin/python3.11
23:28:18.865 [debug] Web view is ready to receive widget messages
23:28:18.871 [debug] Widget Message: Received IPyWidgets_kernelOptions in ScriptManager
23:28:18.872 [debug] Widget Message: Received IPyWidgetMessages.IPyWidgets_kernelOptions
23:28:18.872 [debug] Widget Message: data-base-url set to http://localhost:8289/
23:28:18.877 [debug] Widget Message: Received IPyWidgets_kernelOptions in ScriptManager
23:28:18.877 [debug] Widget Message: Received IPyWidgetMessages.IPyWidgets_kernelOptions
23:28:18.877 [debug] Widget Message: data-base-url set to http://localhost:8289/

Coding Language and Runtime Version

Python

Language Extension Version (if applicable)

No response

Anaconda Version (if applicable)

No response

Running Jupyter locally or remotely?

Remote