Repository: spyder-ide/spyder

Issue:
Error when clearing variables in the Variable Explorer
## Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->

Hello Team,

I recently updated my spyder application from 3 to 4 version, but after update, the variable explorer is not getting cleared.

So request you to please help me.

Thank You
Rohit Mathur

### Traceback
```python-traceback
Exception in comms call remove_value:
  File "C:\Users\rohit\Anaconda3\lib\site-packages\spyder_kernels\comms\commbase.py", line 342, in _handle_remote_call
    buffer['call_kwargs'])
  File "C:\Users\rohit\Anaconda3\lib\site-packages\spyder_kernels\comms\commbase.py", line 353, in _remote_callback
    *call_args, **call_kwargs)
  File "C:\Users\rohit\Anaconda3\lib\site-packages\spyder_kernels\console\kernel.py", line 236, in remove_value
    ns.pop(name)
KeyError: 'index_exp'
Exception in comms call remove_value:
  File "C:\Users\rohit\Anaconda3\lib\site-packages\spyder_kernels\comms\commbase.py", line 342, in _handle_remote_call
    buffer['call_kwargs'])
  File "C:\Users\rohit\Anaconda3\lib\site-packages\spyder_kernels\comms\commbase.py", line 353, in _remote_callback
    *call_args, **call_kwargs)
  File "C:\Users\rohit\Anaconda3\lib\site-packages\spyder_kernels\console\kernel.py", line 236, in remove_value
    ns.pop(name)
KeyError: 'division'
```

## Versions

* Spyder version: 4.1.2 
* Python version: 3.7.7
* Qt version: 5.9.6
* PyQt5 version: 5.9.2
* Operating System: Windows 10

### Dependencies

```

# Mandatory:
atomicwrites >=1.2.0           :  1.3.0 (OK)
chardet >=2.0.0                :  3.0.4 (OK)
cloudpickle >=0.5.0            :  1.3.0 (OK)
diff_match_patch >=20181111    :  20181111 (OK)
intervaltree                   :  None (OK)
IPython >=4.0                  :  7.13.0 (OK)
jedi =0.15.2                   :  0.15.2 (OK)
nbconvert >=4.0                :  5.6.1 (OK)
numpydoc >=0.6.0               :  0.9.2 (OK)
paramiko >=2.4.0               :  2.7.1 (OK)
parso =0.5.2                   :  0.5.2 (OK)
pexpect >=4.4.0                :  4.8.0 (OK)
pickleshare >=0.4              :  0.7.5 (OK)
psutil >=5.3                   :  5.7.0 (OK)
pygments >=2.0                 :  2.6.1 (OK)
pylint >=0.25                  :  2.4.4 (OK)
pyls >=0.31.9;<0.32.0          :  0.31.9 (OK)
qdarkstyle >=2.8               :  2.8 (OK)
qtawesome >=0.5.7              :  0.7.0 (OK)
qtconsole >=4.6.0              :  4.7.2 (OK)
qtpy >=1.5.0                   :  1.9.0 (OK)
rtree >=0.8.3                  :  0.9.3 (OK)
sphinx >=0.6.6                 :  2.4.4 (OK)
spyder_kernels >=1.9.0;<1.10.0 :  1.9.0 (OK)
watchdog                       :  None (OK)
zmq >=17                       :  18.1.1 (OK)

# Optional:
cython >=0.21                  :  0.29.15 (OK)
matplotlib >=2.0.0             :  3.1.3 (OK)
numpy >=1.7                    :  1.18.1 (OK)
pandas >=0.13.1                :  1.0.3 (OK)
scipy >=0.17.0                 :  1.4.1 (OK)
sympy >=0.7.3                  :  1.5.1 (OK)
```



Discussion:
@dalthviz, please take a look at this one. I don't understand why this is still happening.
> So request you to please help me.

For now the only solution is to restart the kernel, sorry.

Resolving patch:
diff --git a/spyder/plugins/ipythonconsole/widgets/namespacebrowser.py b/spyder/plugins/ipythonconsole/widgets/namespacebrowser.py
--- a/spyder/plugins/ipythonconsole/widgets/namespacebrowser.py
+++ b/spyder/plugins/ipythonconsole/widgets/namespacebrowser.py
@@ -53,7 +53,7 @@ def set_namespacebrowser(self, namespacebrowser):
         """Set namespace browser widget"""
         self.namespacebrowser = namespacebrowser
 
-    def refresh_namespacebrowser(self, interrupt=False):
+    def refresh_namespacebrowser(self, interrupt=True):
         """Refresh namespace browser"""
         if self.kernel_client is None:
             return
diff --git a/spyder/plugins/variableexplorer/widgets/namespacebrowser.py b/spyder/plugins/variableexplorer/widgets/namespacebrowser.py
--- a/spyder/plugins/variableexplorer/widgets/namespacebrowser.py
+++ b/spyder/plugins/variableexplorer/widgets/namespacebrowser.py
@@ -269,7 +269,7 @@ def setup_toolbar(self):
             self,
             text=_("Refresh variables"),
             icon=ima.icon('refresh'),
-            triggered=lambda: self.refresh_table(interrupt=True))
+            triggered=self.refresh_table)
 
         return [load_button, self.save_button, save_as_button,
                 reset_namespace_button, self.search_button,
@@ -375,10 +375,10 @@ def show_finder(self, set_visible=False):
         else:
             self.editor.setFocus()
 
-    def refresh_table(self, interrupt=False):
+    def refresh_table(self):
         """Refresh variable table"""
         if self.is_visible and self.isVisible():
-            self.shellwidget.refresh_namespacebrowser(interrupt=interrupt)
+            self.shellwidget.refresh_namespacebrowser()
             try:
                 self.editor.resizeRowToContents()
             except TypeError:


Test patch:
diff --git a/spyder/app/tests/test_mainwindow.py b/spyder/app/tests/test_mainwindow.py
--- a/spyder/app/tests/test_mainwindow.py
+++ b/spyder/app/tests/test_mainwindow.py
@@ -2751,7 +2751,7 @@ def test_varexp_refresh(main_window, qtbot):
     # This is empty
     assert len(nsb.editor.source_model._data) == 0
 
-    nsb.refresh_table(interrupt=True)
+    nsb.refresh_table()
     qtbot.waitUntil(lambda: len(nsb.editor.source_model._data) == 1)
 
     assert 0 < int(nsb.editor.source_model._data['i']['view']) < 9