python - How to prevent incorrect exit from QTapplication when running from within Spyder -
this question related code shown here
an more down-to-the-point code this:
import sys import os pyqt4 import qtgui class window(qtgui.qdialog): def __init__(self, parent=none): super(window, self).__init__(parent) # button mess around self.button= qtgui.qpushbutton('push me') # set layout layout = qtgui.qvboxlayout() layout.addwidget(self.button) self.setlayout(layout) if __name__ == '__main__': app = qtgui.qapplication(sys.argv) main = window() main.show() sys.exit(app.exec_())
when run this, silly one-button window appears, nothing :-) still, when close it, following complaint ipython
console:
an exception has occurred, use %tb see full traceback.
to exit: use 'exit', 'quit', or ctrl-d. exception has occurred, use %tb see full traceback. systemexit: 0 in [3]: %tb traceback (most recent call last): file "<ipython-input-2-0a8f6cad0df5>", line 1, in <module> runfile('c:/users/my_username/appdata/local/continuum/anaconda3/lib/site-packages/pyqt4/se2.py', wdir='c:/users/mtk10531/appdata/local/continuum/anaconda3/lib/site-packages/pyqt4') file "c:\users\my_username\appdata\local\continuum\anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 682, in runfile execfile(filename, namespace) file "c:\users\my_username\appdata\local\continuum\anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 85, in execfile exec(compile(open(filename, 'rb').read(), filename, 'exec'), namespace) file "c:/users/my_username/appdata/local/continuum/anaconda3/lib/site-packages/pyqt4/se2.py", line 39, in <module> sys.exit(app.exec_()) systemexit: 0
then, running again produces following:
it seems kernel died unexpectedly. use 'restart kernel' continue using console. seems kernel died unexpectedly. use 'restart kernel' continue using console. seems kernel died unexpectedly. use 'restart kernel' continue using console.
i found other posts complaining similar things, here , here
i have tried implement understood (not much) answers, namely:
to pass name of script
qapplication
:app = qtgui.qapplication(['my_file.py'])
had no effectto strip
app = qtgui.qapplication(['my_file.py'])
main()
, in case kernel dies before doing else...
any hint?
cheers, michele
p.s. - looking @ wavy pattern of \
, /
in traceback makes me sick!
Comments
Post a Comment