Escaping Variables Which Conflict With PDB Commands
Sometimes, you will run to run Python commands through the PDB console which will clash with PDB’s own command set. One example would be if you had a variable called c, and wanted to assign to it:
Instead of assigning the variable
c the value
23, PDB will interpret the above
c as it’s continue command. To prevent this from happening, prefix the command with
Entering A Running Python Process
pyrasite-shell is a great tool for attaching to a running Python process. You can install it using
You can then attach a pyrasite shell to a running python process using the process ID (PID):
You should then be presented with an interactive Python shell, and you can do things like print the stack trace for each thread:
Note that annoyingly, coping and pasting this code into the interactive console will not usually work (due to whitespace getting mangled perhaps?).
pyrasite-shell is a great tool for attaching to “hung” or “frozen” Python processes, which might be stuck in a loop or stuck in a blocked state waiting for something to happen.
This work is licensed under a Creative Commons Attribution 4.0 International License .