如何调试 pythonic GUI 程序?
我想调试一个Pythonic程序,例如calibre。通常,我使用 pdb 从控制台进行调试,但是当我将 pdb 与 pythonic 一起使用时GUI 程序,GUI 部分(画布或到底是什么)冻结,并且以这种方式调试真的非常困难。
对于调试 pythonic GUI 程序有什么建议吗?你怎么做?
I want to debug a pythonic program, such as calibre. Normally, I was using pdb to debug from the console, but when I use pdb with pythonic GUI programs, the GUI part (canvas or what the heck it is) freezes and it's really very hard to debug in that way.
Any suggestions for debugging pythonic GUI programs? How do you do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会在 GUI 代码中每个事件处理函数/方法的顶部调用
logging.debug
来表示“用户操作”,即鼠标单击、输入键。此外,任何更新视图的高级函数都会在开头调用logging.debug
。这些日志消息将报告函数/方法中使用的任何重要信息。由于消息是在 DEBUG 级别记录的,因此您可以通过简单的配置更改来打开/关闭它们。或者,虽然不复杂,但甚至忘记
logging
模块并暂时放入print
语句直到发现问题可能会更快。以下是我编写的一些代码,用于使用旋转日志文件初始化
logging
模块:I would place calls to
logging.debug
at the top of each event handler function/method in my GUI code that represents a "user action", i.e. mouse clicks, enter key. Also any high-level function that updates the view would have alogging.debug
call at the beginning. These log messages would report any important information used in the function/method. Because the messages are logged atDEBUG
level, you can turn them on/off with a simple configuration change.Alternatively, while unsophisticated, it might be faster to forget even the
logging
module and put inprint
statements temporarily until you find the problem.Here's some code I wrote to initialize the
logging
module with a rotating log file: