ipython / ipython/ipykernel

AttributeError: 'SpyderKernel' object has no attribute 'app' when calling exit(<number>) in a script

Abierto
#403 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Python
Estrellas
734
Forks
412
Merge medio
1 d 5 h
PR fusionados (30 d)
8

Descripción

I put exit(0) or exit() into a Python script that execute from within Spyder and each time the code line is reached when executing the script in Spyder I get the following:

The script catches the exception and prints the following stack trace via the traceback module:
Traceback (most recent call last):
File "[path]/[scriptFile].py", line 54, in
exit(0)
File "[python36 path]\lib\site-packages\IPython\core\autocall.py", line 70, in \_\_call\_\_
self._ip.ask_exit()
File "[python36 path]\lib\site-packages\ipykernel\zmqshell.py", line 527, in ask_exit
self.exit_now = (not self.keepkernel_on_exit)
File "[python36 path]\lib\site-packages\traitlets\traitlets.py", line 585, in \_\_set\_\_
self.set(obj, value)
File "[python36 path]\lib\site-packages\traitlets\traitlets.py", line 574, in set
obj._notify_trait(self.name, old_value, new_value)
File "[python36 path]\lib\site-packages\traitlets\traitlets.py", line 1139, in _notify_trait
type='change',
File "[python36 path]\lib\site-packages\traitlets\traitlets.py", line 1176, in notify_change
c(change)
File "[python36 path]\lib\site-packages\ipykernel\zmqshell.py", line 476, in _update_exit_now
exit_hook(self.kernel)
File "[python36 path]\lib\site-packages\ipykernel\eventloops.py", line 136, in loop_qt_exit
kernel.app.exit()
AttributeError: 'SpyderKernel' object has no attribute 'app'

The following software is involved:
- Python 3.6.8 in Windows
- ipykernel 5.1.0
- Spyder 3.3.4
- spyder-kernels 0.4.4
- traitlets 4.3.2
- PyQt5 5.12.1
- QtPy 1.7.0

Then the script asks for user input the script halts to give the user time to read the stack trace back. Then the script code ends with exit(1) and the IPython console closes properly. In general exit(1) seems to work fine.

As a test code the following could be used:
```
import traceback

try:
s = input('Was this script running fine? (Y/N) ')
if s.upper() in ['Y', 'Yes']:
exit(0)
else:
exit(1)
except Exception as ex:
import bdb
if type(ex) is KeyboardInterrupt or type(ex) is bdb.BdbQuit:
raise
else:
print('The following exception occured:')
traceback.print_exc()
s = input('Press enter to exit: ')
print('Exitting...')
exit(1)
```

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.