spyder-ide / spyder

Official repository for Spyder - The Scientific Python Development Environment
https://www.spyder-ide.org
MIT License
8.22k stars 1.59k forks source link

Variables are not cleared after restaring the kernel #14481

Open LazyTrader opened 3 years ago

LazyTrader commented 3 years ago

Issue Report Checklist

Problem Description

Restarting the kernel does not clear variables. Attempting to delete them after a kernel restart results in "Exception in comms call remove_value:".

What steps reproduce the problem?

  1. Restart the kernel
  2. Try to delete variables after restarting the kernel

What is the expected output? What do you see instead?

The variables should be cleared after a kernel restart

Paste Traceback/Error Below (if applicable)


Exception in comms call remove_value:

  File "C:\ProgramData\Anaconda3\envs\DeepLearning\lib\site-packages\spyder_kernels\comms\commbase.py", line 340, in _handle_remote_call
    return_value = self._remote_callback(

  File "C:\ProgramData\Anaconda3\envs\DeepLearning\lib\site-packages\spyder_kernels\comms\commbase.py", line 353, in _remote_callback
    return self._remote_call_handlers[call_name](

  File "C:\ProgramData\Anaconda3\envs\DeepLearning\lib\site-packages\spyder_kernels\console\kernel.py", line 203, in remove_value
    ns.pop(name)

KeyError: 'FibonacciLongTemplate'

Exception in comms call remove_value:

  File "C:\ProgramData\Anaconda3\envs\DeepLearning\lib\site-packages\spyder_kernels\comms\commbase.py", line 340, in _handle_remote_call
    return_value = self._remote_callback(

  File "C:\ProgramData\Anaconda3\envs\DeepLearning\lib\site-packages\spyder_kernels\comms\commbase.py", line 353, in _remote_callback
    return self._remote_call_handlers[call_name](

  File "C:\ProgramData\Anaconda3\envs\DeepLearning\lib\site-packages\spyder_kernels\console\kernel.py", line 203, in remove_value
    ns.pop(name)

KeyError: 'FibonacciShortTemplate'

Exception in comms call remove_value:

  File "C:\ProgramData\Anaconda3\envs\DeepLearning\lib\site-packages\spyder_kernels\comms\commbase.py", line 340, in _handle_remote_call
    return_value = self._remote_callback(

  File "C:\ProgramData\Anaconda3\envs\DeepLearning\lib\site-packages\spyder_kernels\comms\commbase.py", line 353, in _remote_callback
    return self._remote_call_handlers[call_name](

  File "C:\ProgramData\Anaconda3\envs\DeepLearning\lib\site-packages\spyder_kernels\console\kernel.py", line 203, in remove_value
    ns.pop(name)

KeyError: 'FinalCash'

Exception in comms call remove_value:

  File "C:\ProgramData\Anaconda3\envs\DeepLearning\lib\site-packages\spyder_kernels\comms\commbase.py", line 340, in _handle_remote_call
    return_value = self._remote_callback(

  File "C:\ProgramData\Anaconda3\envs\DeepLearning\lib\site-packages\spyder_kernels\comms\commbase.py", line 353, in _remote_callback
    return self._remote_call_handlers[call_name](

  File "C:\ProgramData\Anaconda3\envs\DeepLearning\lib\site-packages\spyder_kernels\console\kernel.py", line 203, in remove_value
    ns.pop(name)

KeyError: 'PnL'

Exception in comms call remove_value:

  File "C:\ProgramData\Anaconda3\envs\DeepLearning\lib\site-packages\spyder_kernels\comms\commbase.py", line 340, in _handle_remote_call
    return_value = self._remote_callback(

  File "C:\ProgramData\Anaconda3\envs\DeepLearning\lib\site-packages\spyder_kernels\comms\commbase.py", line 353, in _remote_callback
    return self._remote_call_handlers[call_name](

  File "C:\ProgramData\Anaconda3\envs\DeepLearning\lib\site-packages\spyder_kernels\console\kernel.py", line 203, in remove_value
    ns.pop(name)

KeyError: 'Results'

Exception in comms call remove_value:

  File "C:\ProgramData\Anaconda3\envs\DeepLearning\lib\site-packages\spyder_kernels\comms\commbase.py", line 340, in _handle_remote_call
    return_value = self._remote_callback(

  File "C:\ProgramData\Anaconda3\envs\DeepLearning\lib\site-packages\spyder_kernels\comms\commbase.py", line 353, in _remote_callback
    return self._remote_call_handlers[call_name](

  File "C:\ProgramData\Anaconda3\envs\DeepLearning\lib\site-packages\spyder_kernels\console\kernel.py", line 203, in remove_value
    ns.pop(name)

KeyError: 'StartingCash'

Exception in comms call remove_value:

  File "C:\ProgramData\Anaconda3\envs\DeepLearning\lib\site-packages\spyder_kernels\comms\commbase.py", line 340, in _handle_remote_call
    return_value = self._remote_callback(

  File "C:\ProgramData\Anaconda3\envs\DeepLearning\lib\site-packages\spyder_kernels\comms\commbase.py", line 353, in _remote_callback
    return self._remote_call_handlers[call_name](

  File "C:\ProgramData\Anaconda3\envs\DeepLearning\lib\site-packages\spyder_kernels\console\kernel.py", line 203, in remove_value
    ns.pop(name)

KeyError: 'StartTime'

Versions

Dependencies


# Mandatory:
atomicwrites >=1.2.0            :  1.4.0 (OK)
chardet >=2.0.0                 :  4.0.0 (OK)
cloudpickle >=0.5.0             :  1.6.0 (OK)
diff_match_patch >=20181111     :  20200713 (OK)
intervaltree >=3.0.2            :  3.1.0 (OK)
IPython >=4.0                   :  7.19.0 (OK)
jedi =0.17.2                    :  0.17.2 (OK)
jsonschema >=3.2.0              :  3.2.0 (OK)
nbconvert >=4.0                 :  6.0.7 (OK)
numpydoc >=0.6.0                :  1.1.0 (OK)
paramiko >=2.4.0                :  2.7.2 (OK)
parso =0.7.0                    :  0.7.0 (OK)
pexpect >=4.4.0                 :  4.8.0 (OK)
pickleshare >=0.4               :  0.7.5 (OK)
psutil >=5.3                    :  5.7.2 (OK)
pygments >=2.0                  :  2.7.3 (OK)
pylint >=1.0                    :  2.6.0 (OK)
pyls >=0.36.1;<1.0.0            :  0.36.2 (OK)
pyls_black >=0.4.6              :  0.4.6 (OK)
pyls_spyder >=0.1.1             :  0.3.0 (OK)
qdarkstyle >=2.8                :  2.8.1 (OK)
qtawesome >=0.5.7               :  1.0.1 (OK)
qtconsole >=4.7.7               :  4.7.7 (OK)
qtpy >=1.5.0                    :  1.9.0 (OK)
rtree >=0.8.3                   :  0.9.4 (OK)
setuptools >=39.0.0             :  51.0.0.post20201207 (OK)
sphinx >=0.6.6                  :  3.4.0 (OK)
spyder_kernels >=1.10.0;<1.11.0 :  1.10.1 (OK)
three_merge >=0.1.1             :  0.1.1 (OK)
watchdog >=0.10.3               :  0.10.4 (OK)
zmq >=17                        :  20.0.0 (OK)

# Optional:
cython >=0.21                   :  None (NOK)
matplotlib >=2.0.0              :  3.3.2 (OK)
numpy >=1.7                     :  1.19.2 (OK)
pandas >=1.1.1                  :  1.1.5 (OK)
scipy >=0.17.0                  :  1.5.2 (OK)
sympy >=0.7.3                   :  None (NOK)
ccordoba12 commented 3 years ago

Hey @LazyTrader, thanks for reporting. We'll try to fix this problem in our 4.2.2 version, to be released in mid February.

In the meantime, I'm afraid you'll have to open a new console instead of restarting the kernel of the current one to avoid this bug.

LazyTrader commented 3 years ago

Thank you :) Keep up the great work!

VeloSteve commented 1 year ago

This is happening to me in Spyder 5.4.2. Trash can icon in explorer: no change Restart kernel from Consoles menu: no change Refresh icon after either of the actions above: no change

Start a new console: Variable Explorer is cleared in the new console

This happens only when I get a Traceback after a window is open, and then close that window by clicking its "X" icon. I happen to be using tkinter. If the stack trace comes before the window is open or if the program runs cleanly, Variable Explorer can still be cleared normally.

ccordoba12 commented 1 year ago

This happens only when I get a Traceback after a window is open

What traceback and window are you referring to? Please be more specific. If you can post that traceback here, then we can analyze it and see how to fix this error.

VeloSteve commented 1 year ago

Here is a small example, crudely cut down from a project I was starting. It seems that any Traceback will do. Here I am calling a nonexistent function, crash_here(), on an instance of Tk. If called before the frames are built there is no problem. If called after, the variables will not clear.

from tkinter import Tk
from tkinter import  LabelFrame, Listbox, Variable
#from tkinter import DISABLED, SUNKEN
from tkinter import N, S, W, E
from tkinter.constants import SINGLE, EXTENDED

root = Tk()
root.title("Frame Intro")
#root.iconbitmap("OY.ico")
root.geometry("800x800")

root.grid_rowconfigure(0, weight=1)
root.grid_columnconfigure(2, weight=1)

# Calling this here does NOT trigger the bug.
#root.crash_here()

print("Building frames")

dirVar = Variable()
frame_files = Listbox(root, listvariable=dirVar, selectmode=SINGLE)
frame_files.grid(row=0, column=0, padx=10, pady=10, sticky=N+S) # pad outside the frame

frame_thumbs = LabelFrame(root, text="Thumbs", padx=50, pady=50) # pad inside the frame
frame_thumbs.grid(row=0, column=1, padx=10, pady=10, sticky=N+S) # pad outside the frame

root.crash_here()

root.mainloop()
ccordoba12 commented 1 year ago

Ok, thanks for the code example @VeloSteve. I can't reproduce this error on Linux though.

@dalthviz, could you check on Windows?

ccordoba12 commented 1 year ago

An additional question for you @VeloSteve: did you set the console Graphics backend to be Tkinter in our Preferences?

dalthviz commented 1 year ago

Running the example code on Windows with the latest Spyder standalone installer version (5.4.2), using the default interpreter the Tkinter graphics backend and the default run settings, I got traceback in the Console and a Tkinter window. While the Tkinter window was still open I cleared the variables from the variable explorer and that worked but I had to manually close the window. Restarting the kernel while the window was being shown also worked but the window closed automatically. I tested using the default interpreter and the Tkinter graphics backend.

However, running with the Directly enter debugging when errors appear caused the variable explorer to not fully empty the variables and I got still two variables (after clearing the variables and restarting the kernel):

imagen

Not totally sure but could those be the variables not cleared?

ccordoba12 commented 1 year ago

Thanks @dalthviz for the additional testing! I can confirm your findings: if you try to remove all variables while you're debugging, then the variable explorer leaves attr and self behind.

@impact27, could you take a look at this one?

RandomEconomist commented 10 months ago

I have the same problem. Variables are never cleared after restarting the kernel. I use Spyder 5.4.3. on windows 11.