|Version 7 (modified by Jamie Turner <jamwt@…>, 9 years ago) (diff)|
Integrating mod_python with TurboGears .8a1
Thanks to Jamie's wonderful mpcp script, this could not have been easier. As always, this is what worked for me. YMMV. And $TG_MP = [your turbogears project directory].
Go grab the mpcp.py from http://www.jamwt.com/ and put it into $TG_MP. Or, if you use setuptools/easy_install, you can do 'easy_install -Z mpcp'; make sure to include the '-Z'.
Put an .htaccess file in $TG_MP with the following:
SetHandler mod_python PythonHandler mpcp PythonDebug On PythonOption cherrysetup $NAME_OF_YOUR_START_SCRIPT::mp_setup
Warning! The start script is usually MyAppName?-start.py, and the dash will screw up the PythonOption. Ergo, lose the dash and there shouldn't be any problems.
Now, in your (newly renamed) MyAppName_start.py make the following changes:
1) move cherrypy.server.start() so it only starts if name == "main".
if __name__ == "__main__": cherrypy.server.start()
2) create a new no-op method, called mp_setup(). As such:
def mp_setup(): pass
This method is supposed to have cherrypy production config stuff, but our prod.cfg file handles that, so make it a no-op. The better solution would be to remove the line in mpcp that looks for cherrysetup, but that's something I'll worry about when a push to production is near.
Note: Previously, there were some instructions on how to get mpcp.py working with the new thread handling in CherryPy?. Jamie seems to have updated mpcp to work with the new setup, so the instructions have been removed. I recommend getting the newest version to work with (version 1.2), instead of hacking up your local copy.