ipython / ipython/ipykernel

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

未關閉
#403 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Python
星號
734
分支
412
平均合併
1 天 5 小時
30 天內合併 PR
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 摘要。