I understand there are ways of writing a Python script so that upon execution from the terminal you will be entered into the interpreter with the ending state of the variables preserved.
Is it possible to cut off a python script mid-execution and go into the interpreter with the state at that point in the script preserved? For example, I have a large loop, which at every iteration enters a new key,value pair into a dictionary. At the end of the loop the dictionary is written out to a file. Upon running the script now for a couple hours, I realize that its not worth letting it finish, but I would still like to see the dictionary up to this point.
The script is running in my terminal right now - is there any to jump to the interpreter from here and see the current state of the dictionary?
EDIT: entering into interpreter AFTER running script (with state preserved)
python -i script.py