CARVIEW |
Select Language
HTTP/2 200
date: Fri, 10 Oct 2025 11:20:08 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: 01K76XK1K9A4Y7B49964J1QXXM-bom
Running gdb against a Python process in a running Docker container | Simon Willison’s TILs
Running gdb against a Python process in a running Docker container
While investigating Datasette issue #1268 I found myself with a Python process that was hanging, and I decided to try running gdb
against it based on tips in Debugging of CPython processes with gdb
Here's the recipe that worked:
- Find the Docker container ID using
docker ps
- in my case it was16197781a7b5
- Attach a new bash shell to that process in privileged mode (needed to get
gdb
to work):docker exec --privileged -it 16197781a7b5 bash
- Install
gdb
and the Python tooling for using it:apt-get install gdb python3-dbg
- Use
top
to find the pid of the running Python process that was hanging. It was20
for me. - Run
gdb /usr/bin/python3 -p 20
to launchgdb
against that process - In the
(gdb)
prompt runpy-bt
to see a backtrace.
I'm sure there's lots more that can be done in gdb
at this point, but that's how I got to a place where I could interact with the Python process that was running in the Docker container.
Related
- docker Attaching a bash shell to a running Docker container - 2020-08-10
- docker Run pytest against a specific Python version using Docker - 2022-09-05
- python Tracing every executed Python statement - 2021-03-21
- sqlite Using LD_PRELOAD to run any version of SQLite with Python - 2020-06-17
- github-actions Talking to a PostgreSQL service container from inside a Docker container - 2020-09-18
- python Debugging a Click application using pdb - 2020-09-03
- github Running a Django and PostgreSQL development environment in GitHub Codespaces - 2023-08-10
- macos Running Docker on an M1 Mac - 2021-05-25
- docker Installing packages from Debian unstable in a Docker image based on stable - 2021-03-22
- linux Basic strace to see what a process is doing - 2020-09-07
Created 2021-03-21T22:48:21-07:00 · Edit