1.2.9 Starting/Restarting a Python Script (restart, run)

file [filename]

Use filename as the Python program to be debugged. It is compiled and becomes is the program executed when you use the `run' command. If no filename is given, this means to set things so there is no Python file.

restart args...

Restart debugger and program via an exec call. All state is lost, and new copy of the debugger is used.

Sometimes in debugging it is necessary to modify module code when one finds a bugs in them. Python will not notice dynamically that a module has changed and thus not reimport it (which also means that module initialization code is not rerun either). So in such a situation one must use restart rather than run.1.2

run args...

Run or ``soft'' restart the debugged Python program. If a string is supplied, it is split with shlex but preserving embedded quotes. The result is used as the new sys.argv. History, breakpoints, actions and debugger options are preserved. R is a short command alias for run.

You may notice that the sometimes you can step into modules included via an import statement, but after a run this stepping skips over the import rather than goes into it. A similar situation is that you may have a breakpoint set inside class __init__ code, but after issuing run this doesn't seem to get called--and in fact it isn't run again!

That's because in Python the import occurs only once. In fact, if the module was imported before invoking the program, you might not be able to step inside an import the first time as well.

In such a situation or other situations where run doesn't seem to have the effect of getting module initialization code executed, you might try using restart rather than run.


It may be possible to unimport by removing a the module from a namespace, but if there are shared dynamically loaded objects those don't get unloaded.
See About this document... for information on suggesting changes.