Live data from Hacker News

Tracing Python

blog.koehntopp.info

11–14 of 14 posts

Re: Tracing Python

#11
post #7

Python has a built-in API for tracing: https://docs.python.org/3/library/sys.html#sys.settrace Here's an example of how to use it (obviously a minimal case, you can customise your handler do do whatever you need): def mytrace(frame, event, arg): if event == "call": print("call", frame.f_code.co_name, frame.f_locals) elif event == "return": print("return", frame.f_code.co_name, arg) return mytrace import sys sys.settr…

I confess I'm surprised the builtin wasn't one of the demoed options. Curious what the reason is.

I just pushed an addendum, and it is being rendered right now.

Re: Tracing Python

#12
post #6

What's the modern practical use case for tracing in python? Environments without an IDE/remote debugger? I can't recall the last time I needed to enable tracing, in the last couple of decades, besides bash scripts.

Originally the question was "What is Honeycomb.io and Opentracing doing and how can I get this into my existing application?" on IRC. On explaining, the discussion went into various directions (Fred Fish C Debugging Macros and tracing Python).

Re: Tracing Python

#14
post #11
post #7

Earlier quoted context omitted.

I confess I'm surprised the builtin wasn't one of the demoed options. Curious what the reason is.

I just pushed an addendum, and it is being rendered right now.

Kudos on making the update! Makes sense that you might not find it if you didn't know it was there. Python's "batteries included" means most things you may want to do, you should check to see if there is a standard lib option, as well. Sometimes it is barebones enough that you may want more, of course. So, really nice to see all of the options you presented.
Post reply on HN