3 ms·
Dropping in a import pdb; pdb.set_trace() in my pytests and running them from the terminal has helped me squash some pretty difficult bugs. It’s dead simple (sa
by dc-programmer 4y ago
Dropping in a import pdb; pdb.set_trace() in my pytests and running them from the terminal has helped me squash some pretty difficult bugs. It’s dead simple (same with Ruby pry)
- animal_spirits 4y agoSince python3.8 you can just call `breakpoint()` and it does the same as `import pdb; pdb.set_trace()` Also since were on the topic I started using pdb++ and my debugging got incredibly more efficient. https://github.com/pdbpp/pdbpp https://github.com/pdbpp/pdbpp
- dc-programmer 4y agoNice recs, I’ll have to check pdb++ out. Another tip is to add —-pdb to pytest so that it starts the debugger on each test failure.
- solarmist 4y agoYou should check out ipdb too. That’s my recommendation.
- solarmist 4y agoI like ipdb over pdb. All of the niceties of ipython when debugging. If you export `PYTHONBREAKPOINT=ipdb.set_trace` you can use this ipdb too.
- toomanydoubts 4y agoI also wanna give a shout out to pudb, for those who want a more visual experience. It uses curses to offer a GUI-like debugging experience while on the terminal. Real nice piece of software.
- icedchai 4y agoI do this all the time! I also do this when writing code, like if I'm getting some json blob from an API call, and I'm not quite sure what it is...
- gpderetta 4y agoCan you attach pdb to a running python process these days?
- dc-programmer 4y agoThat’s a good question and would be interested if anyone knows the answer. I used do this a lot with gdb and C++ server code
- dc-programmer 4y agoNow that I think about it I bet you could attach pdb to a process running the python interpreter and find your way to the right level of abstraction. Does not sound practical though
- IshKebab 4y agoPDB is rubbish compared to Debugpy. You should try that instead. With VSCode you get a proper GUI debugging experience.
- dc-programmer 4y agoI’ll check it out. In my current environment I optimize for simplicity and ease of setup, so that means vim + pdb. But that could change in future.