Debugging Externally Launched Code
This section describes how to start debugging from a process that is not launched by Wing. Examples of code that must be launched externally include tasks running under a web server and embedded Python scripts running inside a larger application.
The following instructions can be used to start debugging in externally launched code that is running on the same machine as Wing:
- Copy wingdbstub.py from the install directory listed in Wing's About box into the same directory as the code you want to debug. Make sure that WINGHOME inside wingdbstub.py is set to the full path of your Wing installation.
- At the point where you want debugging to begin, insert the following source code: import wingdbstub. If you are debugging code in an embedded Python instance, see the notes in Debugging Embedded Python Code.
- Make sure the Debugger > Listening > Accept Debug Connections preference is turned on, to allow connection from external processes.
- Set any required breakpoints in your Python source code by clicking on the breakpoint margin to the left of the code in Wing, or with the breakpoint items in the Debug menu.
- Initiate the debug program from outside Wing in a way that causes it to import wingdbstub and reach a breakpoint or exception. You should see the status indicator in the lower left of Wing's window change to yellow, red, or green, as described in Debugger Status. When a breakpoint is reached, Wing should come to the front and show the file where the debugger has stopped. If no breakpoint or exception is reached, the program will run to completion, or you can use the Pause command in the Debug menu.
If you run your debug process as a different user, and in some other cases, Wing will initially refuse the connection and ask you to accept a new security token. After accepting it, debugging again should succeed.
To preauthorize the debug connection, you can copy the file wingdebugpw from your Settings Directory into the same directory as your copy of wingdbstub.py.
If you have problems making this work, try setting the kLogFile variable in wingdbstub.py to log additional diagnostic information.
Section Contents
16.0.1. Externally Launched Process Behavior
16.0.2. Debugging Embedded Python Code
16.0.3. Configuring wingdbstub
16.0.4. Starting Debug Automatically Using sitecustomize
16.0.5. Debugger API