|Version 4 (modified by leo mendoza, 10 years ago) (diff)|
Integrating mod_python with TurboGears .8a1
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. Ideally, you could just grab it from easy_install, but I had a problem getting the mpcp to be seen in mod_python's $PYTHONPATH so that was my workaround.
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". This might be unnecessary, but I really enjoy typing, so whatever.
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, instead of hacking up your local copy.