Repository: spyder-ide/spyder

Issue:
RuntimeError when trying to detect if completion widget is visible after closing editor window
## Description

### What steps will reproduce the problem?

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

I had two editors open, one in spyder another that was seperated. I tried to close the extra one that was seperated.

### Traceback
```python-traceback
  File "C:\Users\racha\anaconda3\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 4208, in mouseMoveEvent
    and not self.is_completion_widget_visible()):
  File "C:\Users\racha\anaconda3\lib\site-packages\spyder\plugins\editor\widgets\base.py", line 927, in is_completion_widget_visible
    return self.completion_widget.isVisible()
RuntimeError: wrapped C/C++ object of type CompletionWidget has been deleted
Traceback (most recent call last):
  File "C:\Users\racha\anaconda3\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 663, in _handle_hover
    elif not self.is_completion_widget_visible():
  File "C:\Users\racha\anaconda3\lib\site-packages\spyder\plugins\editor\widgets\base.py", line 927, in is_completion_widget_visible
    return self.completion_widget.isVisible()
RuntimeError: wrapped C/C++ object of type CompletionWidget has been deleted
Traceback (most recent call last):
  File "C:\Users\racha\anaconda3\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 4208, in mouseMoveEvent
    and not self.is_completion_widget_visible()):
  File "C:\Users\racha\anaconda3\lib\site-packages\spyder\plugins\editor\widgets\base.py", line 927, in is_completion_widget_visible
    return self.completion_widget.isVisible()
RuntimeError: wrapped C/C++ object of type CompletionWidget has been deleted
Traceback (most recent call last):
  File "C:\Users\racha\anaconda3\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 4208, in mouseMoveEvent
    and not self.is_completion_widget_visible()):
  File "C:\Users\racha\anaconda3\lib\site-packages\spyder\plugins\editor\widgets\base.py", line 927, in is_completion_widget_visible
    return self.completion_widget.isVisible()
RuntimeError: wrapped C/C++ object of type CompletionWidget has been deleted
Traceback (most recent call last):
  File "C:\Users\racha\anaconda3\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 4208, in mouseMoveEvent
    and not self.is_completion_widget_visible()):
  File "C:\Users\racha\anaconda3\lib\site-packages\spyder\plugins\editor\widgets\base.py", line 927, in is_completion_widget_visible
    return self.completion_widget.isVisible()
RuntimeError: wrapped C/C++ object of type CompletionWidget has been deleted
Traceback (most recent call last):
  File "C:\Users\racha\anaconda3\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 4208, in mouseMoveEvent
    and not self.is_completion_widget_visible()):
  File "C:\Users\racha\anaconda3\lib\site-packages\spyder\plugins\editor\widgets\base.py", line 927, in is_completion_widget_visible
    return self.completion_widget.isVisible()
RuntimeError: wrapped C/C++ object of type CompletionWidget has been deleted
Traceback (most recent call last):
  File "C:\Users\racha\anaconda3\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 4208, in mouseMoveEvent
    and not self.is_completion_widget_visible()):
  File "C:\Users\racha\anaconda3\lib\site-packages\spyder\plugins\editor\widgets\base.py", line 927, in is_completion_widget_visible
    return self.completion_widget.isVisible()
RuntimeError: wrapped C/C++ object of type CompletionWidget has been deleted
Traceback (most recent call last):
  File "C:\Users\racha\anaconda3\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 4208, in mouseMoveEvent
    and not self.is_completion_widget_visible()):
  File "C:\Users\racha\anaconda3\lib\site-packages\spyder\plugins\editor\widgets\base.py", line 927, in is_completion_widget_visible
    return self.completion_widget.isVisible()
RuntimeError: wrapped C/C++ object of type CompletionWidget has been deleted
Traceback (most recent call last):
  File "C:\Users\racha\anaconda3\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 4208, in mouseMoveEvent
    and not self.is_completion_widget_visible()):
  File "C:\Users\racha\anaconda3\lib\site-packages\spyder\plugins\editor\widgets\base.py", line 927, in is_completion_widget_visible
    return self.completion_widget.isVisible()
RuntimeError: wrapped C/C++ object of type CompletionWidget has been deleted
Traceback (most recent call last):
  File "C:\Users\racha\anaconda3\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 4208, in mouseMoveEvent
    and not self.is_completion_widget_visible()):
  File "C:\Users\racha\anaconda3\lib\site-packages\spyder\plugins\editor\widgets\base.py", line 927, in is_completion_widget_visible
    return self.completion_widget.isVisible()
RuntimeError: wrapped C/C++ object of type CompletionWidget has been deleted
Traceback (most recent call last):
  File "C:\Users\racha\anaconda3\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 4208, in mouseMoveEvent
    and not self.is_completion_widget_visible()):
  File "C:\Users\racha\anaconda3\lib\site-packages\spyder\plugins\editor\widgets\base.py", line 927, in is_completion_widget_visible
    return self.completion_widget.isVisible()
RuntimeError: wrapped C/C++ object of type CompletionWidget has been deleted
Traceback (most recent call last):
  File "C:\Users\racha\anaconda3\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 4208, in mouseMoveEvent
    and not self.is_completion_widget_visible()):
  File "C:\Users\racha\anaconda3\lib\site-packages\spyder\plugins\editor\widgets\base.py", line 927, in is_completion_widget_visible
    return self.completion_widget.isVisible()
RuntimeError: wrapped C/C++ object of type CompletionWidget has been deleted
Traceback (most recent call last):
  File "C:\Users\racha\anaconda3\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 663, in _handle_hover
    elif not self.is_completion_widget_visible():
  File "C:\Users\racha\anaconda3\lib\site-packages\spyder\plugins\editor\widgets\base.py", line 927, in is_completion_widget_visible
    return self.completion_widget.isVisible()
RuntimeError: wrapped C/C++ object of type CompletionWidget has been deleted
```

## Versions

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

### Dependencies

```
atomicwrites >=1.2.0         :  1.4.0 (OK)
chardet >=2.0.0              :  3.0.4 (OK)
cloudpickle >=0.5.0          :  1.5.0 (OK)
diff_match_patch >=20181111  :  20181111 (OK)
intervaltree                 :  None (OK)
IPython >=4.0                :  7.16.1 (OK)
jedi =0.14.1                 :  0.14.1 (OK)
nbconvert >=4.0              :  5.6.1 (OK)
numpydoc >=0.6.0             :  1.1.0 (OK)
pexpect >=4.4.0              :  4.8.0 (OK)
pickleshare >=0.4            :  0.7.5 (OK)
psutil >=0.3                 :  5.7.0 (OK)
pygments >=2.0               :  2.6.1 (OK)
pylint >=0.25                :  2.4.4 (OK)
pyls >=0.31.2;<0.32.0        :  0.31.7 (OK)
zmq >=17                     :  19.0.1 (OK)
qdarkstyle >=2.7             :  2.8.1 (OK)
qtawesome >=0.5.7            :  0.7.2 (OK)
qtconsole >=4.6.0            :  4.7.5 (OK)
qtpy >=1.5.0                 :  1.9.0 (OK)
rtree >=0.8.3                :  0.9.4 (OK)
sphinx >=0.6.6               :  3.1.2 (OK)
spyder_kernels >=1.8.1;<2.0.0:  1.8.1 (OK)
watchdog                     :  None (OK)
cython >=0.21                :  0.29.20 (OK)
matplotlib >=2.0.0           :  3.2.2 (OK)
numpy >=1.7                  :  1.18.5 (OK)
pandas >=0.13.1              :  1.0.5 (OK)
scipy >=0.17.0               :  1.5.0 (OK)
sympy >=0.7.3                :  1.6.1 (OK)
```



Discussion:
Thanks for reporting. We'll fix this in our next version.
@steff456, we simply need to catch the `RuntimeError` on the line that generates it and pass.

Resolving patch:
diff --git a/spyder/plugins/editor/widgets/base.py b/spyder/plugins/editor/widgets/base.py
--- a/spyder/plugins/editor/widgets/base.py
+++ b/spyder/plugins/editor/widgets/base.py
@@ -912,7 +912,12 @@ def insert_completion(self, completion, completion_position):
 
     def is_completion_widget_visible(self):
         """Return True is completion list widget is visible"""
-        return self.completion_widget.isVisible()
+        try:
+            return self.completion_widget.isVisible()
+        except RuntimeError:
+            # This is to avoid a RuntimeError exception when the widget is
+            # already been deleted. See spyder-ide/spyder#13248.
+            return False
 
     def hide_completion_widget(self, focus_to_parent=True):
         """Hide completion widget and tooltip."""


Test patch: