question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

In new native interactive window, restarting the kernel does not clear imported modules

See original GitHub issue

Environment 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]

  1. 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
  1. 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.
  2. make some modification to my_fun, for instance add another line like print('now I am printing an extra line').
  3. 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.
  4. 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 (ViewOutput, change the drop-down the upper-right of the Output panel to Jupyter)

XXX

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
joyceerhlcommented, Aug 10, 2021

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.

0reactions
joyceerhlcommented, Aug 31, 2021

Sounds like this issue has been fixed–please file a new issue if this is not working for you.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found