Method to peek at a running Python program

As seen on stackoverflow

If you place

import code

at any point in your script, python will instantiate a python shell at exactly that point that has access to everything in the state of the script at that point.
^D exits the shell and resumes execution past that point.

You can even modify the state at that point from the shell, call functions, etc.

Leave a Reply