Wing IDE is an integrated development environment that can be used to write, test, and debug Python code that is run by the mod_python module for the Apache web server. Wing provides auto-completion, call tips, a powerful debugger, and many other features that help you write, navigate, and understand Python code.
To get started using Wing, refer to the tutorial in the Help menu in Wing and/or the Wing IDE 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 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.
- 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"): 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.
In some cases, we've seen Wing fail to debug the second+ request to mod_python. If this happens, try the following variant of the above code:
import wingdbstub import time if wingdbstub.debugger != None: wingdbstub.debugger.StopDebug() time.sleep(2) wingdbstub.debugger.StartDebug()
This reinitialized debugging with each page load. The time.sleep() duration may be shortened, or may need to be lengthened if Wing does not manage to drop the debug connection and initiate listening for a new connection quickly enough.
|« 2.7. Using Wing IDE with mod_wsgi||Table of Contents||2.9. Using Wing IDE with Paste and Pylons »|