Home » Support » Index of All Documentation » Wing Pro Reference Manual » Advanced Debugging Topics » Debugging Externally Launched Code »

Debugging Embedded Python Code


When Python code is run by an interpreter embedded in a larger application, you may need to craft special code to make debugging work properly.

If the host application is simply creating a single Python instance and reusing it for all script invocations, in most cases setting kEmbedded=1 in wingdbstub.py will suffice.

In certain cases where the host application is manually creating or altering the thread state for each invocation of a script, you may need to use code as follows to reset the debugger and connection for each script invocation:

import wingdbstub

In other cases where the host application uses an entirely different Python instance for each invocation, you may need to arrange that the Debugger API function ProgramQuit is called before each instance is destroyed and may also want to leave kEmbedded=0 in wingdbstub.py. In this case you may also need to unset the environment variable WINGDB_ACTIVE before importing wingdbstub, as this may be left in the environment by the host application and will prevent wingdbstub from initiating debug in the second or later Python instance.

Debugging Embedded Python Code