Home » Support » Index of All Documentation » How-Tos » How-Tos for Web Development »
3.7. Using Wing IDE with mod_python
Wing IDE is an integrated development environment for the Python programming language. Wing can be used to debug code that is run by the mod_python module for the Apache web server. This document assumes mod_python is installed and Apache is configured to use it; please see the installation chapter of the mod_python manual for information on how to install it.
Since Wing's debugger takes control of all threads in a process, only one http request can be debugged at a time. In the technique described below, a new debugging session is created for each request and the session is ended when the request processing ends. If a second request is made while one is being debugged, it will block until the first request completes. This is true of requests processed by a single Python module and it is true of requests processed by multiple Python modules in the same Apache process and its child processes. As a result, it is recommended that only one person debug mod_python based modules per Apache instance and production servers should not be debugged.
Quick Start
- Copy wingdbstub.py from the Wing IDE installation directory into either the directory the module is in or another directory in the Python path used by the module.
- Edit wingdbstub.py if needed so the settings match the settings in your preferences. Typically, nothing needs to be set unless Wing's debug preferences have been modified. If you do want to alter these settings, see the Remote Debugging section of the Wing IDE reference manual for more information.
- Copy wingdebugpw from your User Settings Directory into the directory that contains the module you plan to debug. This step can be skipped if the module to be debugged is going to run on the same machine and under the same user as Wing IDE. The wingdebugpw file must contain exactly one line.
- Insert import wingdbstub at the top of the module imported by the mod_python core.
- Insert if wingdbstub.debugger != None: wingdbstub.debugger.StartDebug() at the top of each function that is called by the mod_python core.
- Enable passive listening in Wing by setting the Enable Passive Listen preference to true.
- Restart Apache and load a URL to trigger the module's execution.
Example
To debug the hello.py example from the Publisher chapter of the mod_python tutorial, modify the hello.py file so it contains the following code:
import wingdbstub
def say(req, what="NOTHING"):
if wingdbstub.debugger != None:
wingdbstub.debugger.StartDebug()
return "I am saying %s" % what
And set up the mod_python configuration directives for the directory that hello.py is in as follows:
AddHandler python-program .py PythonHandler mod_python.publisher
Then set a breakpoint on the return "I am saying %s" % what line, make sure Wing is listening for a debug connection, and load http://[server]/[path]/hello.py in a web browser (substitute appropriate values for [server] and [path]). Wing should then stop at the breakpoint.
Related Documents
- Wing IDE Reference Manual, which describes Wing IDE in detail.
- Mod_python Manual, which describes how to install, configure, and use mod_python.
| « 3.6. Using Wing IDE with Webware | Table of Contents | 3.8. Debugging Web CGIs with Wing IDE » |
