ipython / ipython/ipykernel

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

オープン
#403 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Python
スター
734
フォーク
412
平均マージ
1日 5時間
マージ済み PR(30日)
8

説明

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

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。