Newsletter
TechAnV Blog
Get updates on security engineering, Rust, eBPF, and DevSecOps. No spam, unsubscribe anytime.
Check your inbox and click the confirmation link to complete your subscription.
Tracing every executed Python statement#
Today I learned how to use the Python trace module to output every single executed line of Python code in a program - useful for figuring out exactly when a crash or infinite loop happens.
The basic format is to run:
1python3 -m trace --trace myscript.pyThis will execute the script and print out every single line of code as it executes - which can be a LOT of output. It slows the program down to a crawl - just starting up Datasette took probably over a minute and churned through hundreds of thousands of lines of console output.
Since Datasette is a command-line application, I needed to use the following recipe to trace it:
1python3 -m trace --trace $(which datasette) fixtures.db -p 8002