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

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

Closed
filipporemonato opened this issue Aug 10, 2021 · 8 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster interactive-window Impacts interactive window

Comments

@filipporemonato
Copy link

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

@filipporemonato filipporemonato added the bug Issue identified by VS Code Team member as probable bug label Aug 10, 2021
@IanMatthewHuff
Copy link
Member

@filipporemonato Thanks for the detailed repro steps here. I do repro both the issue with the variables not showing up until code is run in the IW as well as the issue with variables not being cleared on a restart. However I did see the new line that I added being printed when added to run_test.py ('Extra line added is what I added). Are you sure that you are not seeing the line added from the file change?
image
@joyceerhl I think the variables not initially showing (+ not clearing on restart) might be a known issue already?

@joyceerhl
Copy link
Contributor

Variables not initially showing is tracked in #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.

@filipporemonato
Copy link
Author

Hei @IanMatthewHuff thanks for checking this out. Good you could repro the variables showing/clearing. I'm unsure why you could not repro the module reload; this is what I see:
image

As you can see the output does not change after restarting the kernel.
This is how my_fun was before the restart:
image

And this is after the restart:
image

I also made sure the modified file was saved before running the import again, and also tried again by saving it before restarting the kernel.

@greazer greazer assigned joyceerhl and unassigned IanMatthewHuff Aug 12, 2021
@greazer greazer added this to the July 2021 Recovery milestone Aug 12, 2021
@greazer greazer added the interactive-window Impacts interactive window label Aug 12, 2021
@joyceerhl
Copy link
Contributor

@filipporemonato Do you happen to have jupyter.runStartupCommands configured to something in your user settings, and are you relying on that for module reload? If so, we're fixing an issue where the startup commands aren't rerun after restarting the kernel and this issue would be a dupe of #7016.

@joyceerhl joyceerhl added the info-needed Issue requires more information from poster label Aug 12, 2021
@filipporemonato
Copy link
Author

Hei @joyceerhl , no I don't have jupyter.runStartupCommands configured in settings:
image

It's worth mentioning that opting out of the new native interactive window thourgh the last line in the settings posted above solves the issue, i.e. the modules get reloaded correctly.

@yourPhysio
Copy link

I am facing the same issue with restart kernel. Does not update the imported modules.

@filipporemonato
Copy link
Author

filipporemonato commented Aug 23, 2021

Hi @joyceerhl, some days ago there has been a small update of VS Code; now I have version 1.59.1 (was 1.59.0).
This update seems to have fixed the issue about modules not being reloaded; now I can see the changes I make in the imported functions pop up in the native interactive window as expected.
If @yourPhysio could confirm, then we can consider this part resolved, and then this issue would become a dupe of #6993 as you mentioned so we can close it.

@joyceerhl joyceerhl modified the milestones: August 2021, September 2021 Aug 24, 2021
@joyceerhl
Copy link
Contributor

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

@joyceerhl joyceerhl removed this from the September 2021 milestone Aug 31, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 8, 2021
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 interactive-window Impacts interactive window
Projects
None yet
Development

No branches or pull requests

5 participants