Spyder: Spyder 4.1 quits when closing browser tab from vpython

Created on 13 Apr 2020  Â·  16Comments  Â·  Source: spyder-ide/spyder

Description

What steps will reproduce the problem?

When using the python code below, the display is correct, but closing the browser tabe with the vpython display will cause Spyder to crash without error message. This only occurs for Windows 10, not macOS. Only Firefox has been tested as a browser. Versions used: python 3.7.7, Spyder 4.1.2, vpython 7.6.1. This bug does NOT occur with Spyder 4.0.1!


from vpython import canvas, color, sphere, vector

def provoke():
scene=canvas(title="view",width=800,height=800)
scene.background=color.white
c = vector(0.8, 0.0, 0.6)
p = vector(0,0,0)
s = sphere(pos=p, radius=8.0, color=c)

provoke()

Versions

  • Spyder version: 4.0.1
  • Python version: 3.7.5
  • Qt version: 5.9.6
  • PyQt5 version: 5.9.2
  • Operating System: Windows 10

Dependencies

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.14.1                 :  0.14.1 (OK)
nbconvert >=4.0              :  5.6.1 (OK)
numpydoc >=0.6.0             :  0.9.2 (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.9 (OK)
zmq >=17                     :  18.1.1 (OK)
qdarkstyle >=2.7             :  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.8.1;<2.0.0:  1.8.1 (OK)
watchdog                     :  None (OK)
cython >=0.21                :  None (NOK)
matplotlib >=2.0.0           :  None (NOK)
numpy >=1.7                  :  1.18.1 (OK)
pandas >=0.13.1              :  None (NOK)
scipy >=0.17.0               :  1.4.1 (OK)
sympy >=0.7.3                :  None (NOK)
IPython Console Bug upstream

All 16 comments

@dalthviz, please take a look at this one.

@ccordoba12 @RussAtkinson after testing this I can confirm Spyder closes if you close the tab. This is the traceback when running with --debug-info verbose:

Handling signal: 0
Traceback (most recent call last):
  File "C:\Users\Daniel\Documents\Spyder\spyder\spyder\widgets\dock.py", line 35, in eventFilter
    def eventFilter(self, obj, event):
KeyboardInterrupt

Pinging @mwcraig about this one. Any pointers on how we could avoid the crash?

After more testing seems like vpython raises a KeyboardInterrupt when closing the tab (you can see the traceback running the code as a script using the Execute in an external system terminal with the Interact with the Python console after execution option checked):

>>>
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Daniel\Anaconda3\envs\develop\lib\site-packages\vpython\no_notebook.py", line 27, in signal_handler
    stop_server()
  File "C:\Users\Daniel\Anaconda3\envs\develop\lib\site-packages\vpython\no_notebook.py", line 327, in stop_server
    raise KeyboardInterrupt
KeyboardInterrupt

@dalthviz, what happens if we catch the KeyboardInterrupt in dock.py?

I changed the eventFilter code to this:

    def eventFilter(self, obj, event):
        """Filter mouse press events.

        Events that are captured and not propagated return True. Events that
        are not captured and are propagated return False.
        """
        try:
            event_type = event.type()
            if event_type == QEvent.MouseButtonPress:
                self.tab_pressed(event)
                return False
            return False
        except Exception:
            return True

But Spyder keeps closing. Should the handle be done somewhere else?

I really don't know. Let's wait for @mwcraig input before proceeding further.

Ok :+1:
Also, as @RussAtkinson explains, this doesn't happen with Spyder 4.0.1. Maybe the handling of the KeyboardInterrupt error changed between spyder-kernels 1.8.1 and 1.9.0?

Ok, that means this is a problem with our kernel. Therefore, I think you need to check the PRs that were merged between 1.8.1 and 1.9.0 and try to detect what code in them could have introduced this bug (I'm not really sure which one could be the culprit, sorry).

Also, for some reason this happens with Windows 10 but not macOS. That
might help focus the search on OS dependent differences.

On Wed, Apr 15, 2020 at 8:36 AM Carlos Cordoba notifications@github.com
wrote:

Ok, that means this is a problem with our kernel. Therefore, I think you
need to check the PRs that were merged between 1.8.1 and 1.9.0 and try to
detect what code in them could have introduced this bug (I'm not really
sure which one could be the culprit, sorry).

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/spyder-ide/spyder/issues/12300#issuecomment-614208539,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AJPQDYWK55YQMTE3XDRVEKLRMX5EVANCNFSM4MGWZRRA
.

Notes:

  • Seems like after the close of the browser tab in Spyder 4.0.1 the kernel is restarted. However running the script again causes Spyder to crash unless you use a dedicated console:
2020-04-16 13:16:49,254 [INFO] [traitlets] -> KernelRestarter: restarting kernel (1/5), keep random ports
2020-04-16 13:16:49,254 [WARNING] [traitlets] -> kernel restarted
2020-04-16 13:16:49,256 [DEBUG] [traitlets] -> Starting kernel: ['C:\\Users\\Daniel\\Anaconda3\\envs\\spyder4.0.1\\pythonw.exe', '-m', 'spyder_kernels.console', '-f', 'C:\\Users\\Daniel\\AppData\\Roaming\\jupyter\\runtime\\kernel-bd2ae532a18c.json']
2020-04-16 13:16:49,259 [DEBUG] [traitlets] -> Connecting to: tcp://127.0.0.1:60641
2020-04-16 13:16:52,256 [DEBUG] [traitlets] -> KernelRestarter: restart apparently succeeded
  • In Spyder 4.1.0 and Spyder 4.1.1 the kernel fails to be restarted but Spyder doesn't close (although the Console where the script was run ends up stuck either using the current console or a dedicated one to run the script):
2020-04-16 13:10:06,020 [INFO] [traitlets] -> KernelRestarter: restarting kernel (1/5), keep random ports
2020-04-16 13:10:06,020 [WARNING] [traitlets] -> kernel restarted
Traceback (most recent call last):
  File "C:\Users\Daniel\Anaconda3\envs\spyder4.1.1\lib\site-packages\psutil\_pswindows.py", line 679, in wrapper
    return fun(self, *args, **kwargs)
  File "C:\Users\Daniel\Anaconda3\envs\spyder4.1.1\lib\site-packages\psutil\_pswindows.py", line 933, in create_time
    user, system, created = cext.proc_times(self.pid)
ProcessLookupError: [Errno 3] No such process (originated from GetExitCodeProcess != STILL_ACTIVE)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Daniel\Anaconda3\envs\spyder4.1.1\lib\site-packages\psutil\__init__.py", line 373, in _init
    self.create_time()
  File "C:\Users\Daniel\Anaconda3\envs\spyder4.1.1\lib\site-packages\psutil\__init__.py", line 723, in create_time
    self._create_time = self._proc.create_time()
  File "C:\Users\Daniel\Anaconda3\envs\spyder4.1.1\lib\site-packages\psutil\_pswindows.py", line 681, in wrapper
    raise convert_oserror(err, pid=self.pid, name=self._name)
psutil.NoSuchProcess: psutil.NoSuchProcess process no longer exists (pid=1536)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Daniel\Anaconda3\envs\spyder4.1.1\lib\site-packages\qtconsole\manager.py", line 27, in poll
    super(QtKernelRestarter, self).poll()
  File "C:\Users\Daniel\Anaconda3\envs\spyder4.1.1\lib\site-packages\jupyter_client\restarter.py", line 113, in poll
    self.kernel_manager.restart_kernel(now=True, newports=newports)
  File "C:\Users\Daniel\Anaconda3\envs\spyder4.1.1\lib\site-packages\jupyter_client\manager.py", line 411, in restart_kernel
    self.shutdown_kernel(now=now, restart=True)
  File "C:\Users\Daniel\Anaconda3\envs\spyder4.1.1\lib\site-packages\jupyter_client\manager.py", line 371, in shutdown_kernel
    self._kill_kernel()
  File "C:\Users\Daniel\Anaconda3\envs\spyder4.1.1\lib\site-packages\spyder\plugins\ipythonconsole\utils\manager.py", line 78, in _kill_kernel
    self.kill_proc_tree(self.kernel.pid)
  File "C:\Users\Daniel\Anaconda3\envs\spyder4.1.1\lib\site-packages\spyder\plugins\ipythonconsole\utils\manager.py", line 44, in kill_proc_tree
    parent = psutil.Process(pid)
  File "C:\Users\Daniel\Anaconda3\envs\spyder4.1.1\lib\site-packages\psutil\__init__.py", line 346, in __init__
    self._init(pid)
  File "C:\Users\Daniel\Anaconda3\envs\spyder4.1.1\lib\site-packages\psutil\__init__.py", line 386, in _init
    raise NoSuchProcess(pid, None, msg)
psutil.NoSuchProcess: psutil.NoSuchProcess no process found with pid 1536
  • In Spyder 4.1.2 Spyder closes either using the current console or a dedicated one to run the script:
Handling signal: 0
Traceback (most recent call last):
  File "C:\Users\Daniel\Anaconda3\envs\develop\lib\site-packages\spyder\widgets\dock.py", line 35, in eventFilter
    def eventFilter(self, obj, event):
KeyboardInterrupt

After a git bisect 1335db55fe70249529e54f72ff768a99743a2d87 show as the first bad commit (taking as bad if the console gets stuck, Spyder doesn't start, or Spyder closes with the close of the browser tab after running the vpython script with a dedicated console). I think it is related with the addition of conda envs activation. Maybe this issue is being caused by the created class SpyderKernelManager that overrides QtKernelManager (?)

I think it is related with the addition of conda envs activation

I think it is too. But I don't understand why the kernel is not restarted correctly in this case.

@goanpeca?

No idea. I cannot look a this right now. Maybe next week.

Ok, please do.

This will be fixed in the next VPython release (don't know when that's going to be released though).

Was this page helpful?
0 / 5 - 0 ratings