CARVIEW |
Select Language
HTTP/2 200
date: Sat, 11 Oct 2025 15:17:11 GMT
server: Fly/6f91d33b9d (2025-10-08)
content-type: text/html; charset=utf-8
content-encoding: gzip
via: 2 fly.io, 2 fly.io
fly-request-id: 01K79XHSPFQQ9AWT81XGA2C07J-bom
Tracing every executed Python statement | Simon Willison’s TILs
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:
python3 -m trace --trace myscript.py
This 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:
python3 -m trace --trace $(which datasette) fixtures.db -p 8002
Related
- docker Running gdb against a Python process in a running Docker container - 2021-03-21
- python Packaging a Python app as a standalone binary with PyInstaller - 2021-01-04
- docker Run pytest against a specific Python version using Docker - 2022-09-05
- sqlite Using LD_PRELOAD to run any version of SQLite with Python - 2020-06-17
- python Debugging a Click application using pdb - 2020-09-03
- python Running PyPy on macOS using Homebrew - 2022-09-14
- python The pdb interact command - 2022-10-31
- python Running Python code in a subprocess with a time limit - 2020-12-06
- cloudrun Tailing Google Cloud Run request logs and importing them into SQLite - 2021-08-09
- git git bisect - 2022-10-29
Created 2021-03-21T22:51:17-07:00 · Edit