Spyder + Python 3.5 - how to debug kernel died, restarting?

喜夏-厌秋 提交于 2019-12-06 09:23:24

问题


I am working for the first time towards the implementation of a very simple GUI in PyQt5, which embeds a matplotlib plot and few buttons for interaction.

I do not really know how to work with classes so I'm making a lot of mistakes, i.e. even if the functionality is simple, I have to iterate a lot between small corrections and verification.

For some reason I would like to debug, however, the whole process is made much, much slower by the fact that at any other try, the python kernel dies and it needs restarting (all done automatically) several times.

That is, every time I try something that should last maybe 5 secs, I end up spending a minute.

Anybody know where to look to spot what is causing these constant death/rebirth circles?

I have been using spyder for some time now and I never experienced this behaviour before, so I'm drawn to think it might have to do with PyQt, but that's about how far I can go.


回答1:


This issue is tracked here

You can learn all the details there, but in a nutshell when running from inside spyder - which itself is a QApplication, the main loop should read:

if __name__ == '__main__':
import sys
from PyQt5 import QtWidgets
fig1 = Figure()
if not QtWidgets.QApplication.instance():
    app = QtWidgets.QApplication(sys.argv)
else:
    app = QtWidgets.QApplication.instance() 
main = Main()
main.addmpl(fig1)
main.show()
sys.exit(app.exec_())

The if/then check on the existence of a QApplication avoids a segmentation fault which happens if one tries to launch multiple instances at one time, as explained here




回答2:


I had a similar problem and found that my application only worked when the graphics settings inside Spyder are set to inline. This can be done at Tools -> Preferences -> IPython console -> Graphics, now change the Backends to inline.

Hope this helps.



来源:https://stackoverflow.com/questions/43328064/spyder-python-3-5-how-to-debug-kernel-died-restarting

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!