When dealing with a misbehaving Python program, classic strategies like adding piles of print statements can be unsatisfying. Fortunately, Python gives us many ways of "looking inside" a running Python process, getting very rich information instantly.
We will look at how we can introspect live Python processes, uncovering what a program is doing, and why it’s doing it. We will also cover pragmatic tips on how to tailor these tools for your own problem’s needs, including when restarting your process isn’t an option!
Python’s runtime offers many helpful hooks into running programs that we can leverage to inspect our running programs. These hooks are lightweight enough that ad-hoc instrumentation tailored to your problem answer tricky questions. On top of that, robust libraries have been built out to work off of these tools
We will talk about techniques and libraries that make it easy to get a high level understanding of:
We will also cover some lightweight tactics that can be used to hack together even more introspection, by only needing to make small tweaks to your code.
I am a software developer currently living in Brisbane. My professional experience is mostly in Python, Django and Typescript, but I have spent a good amount of time using Rust, and am interested in systems programming in general.
I have a tendency to gravitate towards debugging and performance issues, and am always on the lookout for new tactics on these fronts.