ipython / ipython/ipykernel

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

Ouverte
#403 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
Python
Étoiles
734
Forks
412
Merge moyen
1 j 5 h
PR mergées (30 j)
8

Description

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)
```

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.