Using Wing with mod_python
Wing is a Python IDE that can be used to develop, test, and debug Python code that is run by the mod_python module for the Apache web server. Two versions of Wing are appropriate for use with this document: Wing Pro is the full-featured Python IDE for professional programmers, and Wing Personal is a free alternative with reduced feature set.
If you do not already have Wing installed, download it now.
To get started using Wing, refer to the tutorial in the Help menu in Wing or the Quickstart Guide.
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.
- Copy wingdbstub.py (from the install directory listed in Wing's About box) 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 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. 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.
- Allow debug connections to Wing by setting the Accept Debug Connections preference to true.
- Restart Apache and load a URL to trigger the module's execution.
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"): wingdbstub.Ensure() 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.