Tutorial: Remote Debugging
So far we've been debugging code launched from inside of Wing. Wing can also debug processes that are running in a web framework, as scripts in a larger application, or that get launched from the command line.
Let's try this now with example2.py in your tutorial directory. First, copy wingdbstub.py out of install directory listed in Wing's About box. Place this in the same directory as example2.py. Next, click on the bug icon in the lower left of Wing IDE's main window and select Accept Debug Connections. Then set a breakpoint on lines 10 and 22 of example2.py:
If you are working on OS X, using the Windows zip install, or using the Linux tar install of Wing, you will need to edit wingdbstub.py to set WINGHOME to the full path to the Wing IDE installation directory (on OS X, this is the name of Wing's .app directory). This is done automatically by the regular Windows installer and Debian and RPM installs on Linux. If you are using one of those you can skip this step.
Now we're ready to debug example2.py when it is launched from outside of the IDE. To launch it, use the DOS Command prompt on Windows, a bash or similar command prompt on Linux, or Terminal or an xterm on OS X by typing:
You may need to specify the full path to python if it is not on your path.
This should start up the code, print some messages, connect to the IDE, and stop on the breakpoint on line 22. Read through the code and the messages printed to understand what is happening. You can verify that the debugger attached by looking at the color of the bug icon in the lower left of the IDE window, and by hovering the mouse over it:
Once you are stopped at a breakpoint or exception in externally launched code, the debugger works just as it would had you launched the debug process from the IDE. The only difference is that the environment is set up by the process itself and the settings specified in Project Properties and File Properties are not used.
When you continue the debugger from the toolbar or Debug menu, the program should print the value of x and exit.
This is a very simple example to illustrate how externally launched code can be debugged. The import of wingdbstub can also be placed in functions or methods, and there is a debugging API that provides control over starting and stopping debugging.
Using the same mechanism, but with some additional configuration, it is also possible to debug Python code running on another machine. This is documented in Remote Debugging in the Wing IDE manual.