Live data from Hacker News

Guide to Python Debugging

martinheinz.dev

21–30 of 149 posts

Re: Guide to Python Debugging

#21
post #20

When debugging compiled code, I often attach a debugger to the process after it’s started to introspect it. I’ve often wanted to do something similar in Python; does anyone know of a tool that might do something like this?

may be python pdb? https://docs.python.org/3/library/pdb.html

Can I somehow give that a PID so it can inject a set_trace or whatever in the current context?

Re: Guide to Python Debugging

#23
I feel like I got in a time machine ... this like debugging from 1995. In fact, pretty sure I would have rejected this in 1995. Unless you are constrained to doing this on a server or other restricted environment where reproducing locally is not possible, just get a good IDE and set some breakpoints in there.

Re: Guide to Python Debugging

#24

This is a bit of a weird article. It spends most of the time talking about logging, which is somewhat useful for debugging but not really. pdb gets a few lines of description, and that is about it. Personally, I can't live without Pycharm when working with Python purely because of how fantastic the debugging experience is. The integration with the interactive IPython shell is simply fantastic, and the live variable v…

For me pdbpp it's a must, always installed on every venv

Re: Guide to Python Debugging

#25
I've recently started integrating PyCharm's debugger more instead of python native tools and it really has been a life changer!

My favorite tiny unique feature is that it injects variable values as temp comments in the code as the program runs in debug mode. So you're seeing `foo = get_foo() # "bar"` as your code. Really helps to debug complex algorithms when you can see the values right there in the code.

My only problem is that debugger shell feels very clunky with ideaVim plugin, so if someone at JetBrains reading this that would be a very welcome improvement!

Re: Guide to Python Debugging

#26

Earlier quoted context omitted.

I second PyCharm, not only from a debugging perspective but as a whole. I don't understand people struggling with generic text editors, development oriented text tools (sublime etc), or even vscode just because they are free when there is a much better tool money can buy (and PyCharm has a free, community version as well).

I write Python with an enhanced text editor every day and don't struggle in the slightest. It's lightening quick as well. I pull out a proper debugger about twice a year.

What are you working on that you never need to pull out a debugger?

Re: Guide to Python Debugging

#27
I use ipython a lot, and it has a great post-error debugger with `%debug` which drops you in a ipdb shell at the stackframe of the error.

Concerning reloading, I find `%autoreload` much more reliable than `importlib.reload`. The latter can't handle `from lib import foo` or if a dependency inside an imported package changed. `%autoreload` just does this all automagically.

Re: Guide to Python Debugging

#28
post #25

I've recently started integrating PyCharm's debugger more instead of python native tools and it really has been a life changer! My favorite tiny unique feature is that it injects variable values as temp comments in the code as the program runs in debug mode. So you're seeing `foo = get_foo() # "bar"` as your code. Really helps to debug complex algorithms when you can see the values right there in the code. My only pr…

Could you please describe some cases?

Re: Guide to Python Debugging

#29

When debugging compiled code, I often attach a debugger to the process after it’s started to introspect it. I’ve often wanted to do something similar in Python; does anyone know of a tool that might do something like this?

Sibling comment suggests Pyrasite for this: https://github.com/lmacken/pyrasite
Post reply on HN