Spyder + Python 3.5 - 如何调试内核死机,重新启动? [英] Spyder + Python 3.5 - how to debug kernel died, restarting?

查看:37
本文介绍了Spyder + Python 3.5 - 如何调试内核死机,重新启动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次致力于在 PyQt5 中实现一个非常简单的 GUI,它嵌入了一个 matplotlib 图和几个交互按钮.

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.

出于某种原因,我想调试,但是,由于在任何其他尝试中,python 内核都死了,并且需要多次重新启动(全部自动完成),因此整个过程变得非常缓慢.

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.

也就是说,每次我尝试应该持续 5 秒的事情时,我最终都会花费一分钟.

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?

我已经使用 spyder 有一段时间了,我以前从未经历过这种行为,所以我认为这可能与 PyQt 有关,但是这就是我能走多远.

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.

推荐答案

此问题已跟踪 这里

您可以在那里了解所有细节,但简而言之,当从 spyder 内部运行时 - 它本身是一个 QApplication,主循环应为:

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_())

if/then 检查 QApplication 是否存在可以避免分段错误,这种错误在尝试一次启动多个实例时会发生,正如 这里

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

这篇关于Spyder + Python 3.5 - 如何调试内核死机,重新启动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆