admin管理员组文章数量:1410705
I often have to debug the python code by pdb debugger. It happens that it fails due to program errors that should be corrected. The problem is that I have to update the python code and restart the debugger to reach the point where the problem ealier ocurred. It takes time for not trivial programs. Is there a way to keep that python debugger state of execution and have the option to change the code being debugged? Alternatively, is there a way to make some kind of results snapshot of python program time consuming initialication and then try debuggind the code? In the later case I want to restart the program from the snapshot and continue with the updated part of python program.
For debugging I use command line pdb initiated by the breakpoint() or pdb.set_trace() commands.
I often have to debug the python code by pdb debugger. It happens that it fails due to program errors that should be corrected. The problem is that I have to update the python code and restart the debugger to reach the point where the problem ealier ocurred. It takes time for not trivial programs. Is there a way to keep that python debugger state of execution and have the option to change the code being debugged? Alternatively, is there a way to make some kind of results snapshot of python program time consuming initialication and then try debuggind the code? In the later case I want to restart the program from the snapshot and continue with the updated part of python program.
For debugging I use command line pdb initiated by the breakpoint() or pdb.set_trace() commands.
Share edited Mar 10 at 8:38 Anatoly Osipov asked Mar 10 at 8:19 Anatoly OsipovAnatoly Osipov 12 bronze badges1 Answer
Reset to default 0So, pdb doesnt support directly 'saving' your state of program, however, the other ways to debug.
For example
code
module, it has functionallity to update your code during debugging,code.interact(local=globals())
, this allow you to execute your program with any changes during debugging. docsAlso you can use IPython, but its more advanced. Anyways, you can start using it with replacing your
pdb.set_trace
with:
from IPython import embed
embed()
Other options is pytest, but its useful only if you are working in test-driven env. There you can debug your tests without restarting the whole application, pytest --pdb
helps you.
本文标签: updating python code in the middle of debuggingStack Overflow
版权声明:本文标题:updating python code in the middle of debugging - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744856670a2628816.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论