In new native interactive window, restarting the kernel does not clear imported modules
See original GitHub issueEnvironment data
- VS Code version: 1.59.0
- Jupyter Extension version (available under the Extensions sidebar): v2021.8.1195043623
- Python Extension version (available under the Extensions sidebar): v2021.8.1105858891
- OS (Windows | Mac | Linux distro) and version: Windows 10
- Python and/or Anaconda version: Python 3.7.6
- Type of virtual environment used (N/A | venv | virtualenv | conda | …): virtualenv
- Jupyter server running: Local
Expected behaviour
Restarting the kernel should clear all variables and imports
Actual behaviour
After restarting the kernel, the variables remain in displayed in the “variables” tab of jupyter. Querying them from the interactive window’s command line results in the correct “name XX not defined”. However, imported modules are not reloaded
Steps to reproduce:
[NOTE: Self-contained, minimal reproducing code samples are extremely helpful and will expedite addressing your issue]
- Create the following two scripts in the same folder:
test.py
:
#%%
import test_fun as tf
#%%
a = 10
b = 20
# %%
c = tf.my_fun(a)
print(c)
test_fun.py
:
import numpy as np
def my_fun(a):
print('I have received ' + str(a))
return 2*a
- run
test.py
, notice the output is as expected. In passing, note that the variables are NOT present in the “variables” tab, but they appear if, having the tab open, some code is run through the Interactive Window command line. - make some modification to
my_fun
, for instance add another line likeprint('now I am printing an extra line')
. - Restart jupyter kernel by clicking on the “restart” button at the top of the window. Note that the old variables do not disappear from the “variables” tab, however querying them from the Interactive Window comman line results in an expected error as the variable is not in memory.
- re-run
test.py
, notice the new line is not being printed, which means the imported module is not reloaded.
Logs
Output for Jupyter
in the Output
panel (View
→Output
, change the drop-down the upper-right of the Output
panel to Jupyter
)
XXX
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Restarting notebook changes jupyter root directory · Issue #7016
Restarting the kernel changes the root directory according to the source code file location. Actual behaviour. Restarting the kernel keeps ...
Read more >Jupyter / IPython: After editing a module, changes are not ...
1) The simplest and most certain is to restart the ipython kernel after changing an imported module. But this has downsides as well,...
Read more >How to Fix Kernel Error in Jupyter Notebook
So, a kernel error occurs when Jupyter fails to connect with a specific version of Python.
Read more >What to do when things go wrong - The Jupyter Notebook
As a result, when encountering kernel startup issues, again, check the argv stanza and verify it's pointing to a valid file. You may...
Read more >How to restart kernel in VSCode to completely reload imports?
I tried to kill kernel and restart it, saved changes - nothing works, only restarting is need. But it isn't too quick and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Variables not initially showing is tracked in https://github.com/microsoft/vscode-jupyter/issues/6993. Not clearing on restart is a bug, but I’ll add that to #6993 since I should fix both of those issues at the same time.
Sounds like this issue has been fixed–please file a new issue if this is not working for you.