18.3. Running CherryPy on mod_pythonAnother popular deployment option is to use mod_python, which is basically a Python interpreter embedded in each of your web server processes. 18.3.1. Advantages/Drawbacks of Using mod_pythonThe advantages of this method are as follows:
The drawbacks of this method are as follows:
For some people who are using shared hosting, this might be your only option because your ISP will not allow long running processes. 18.3.2. Configuring Apache/CherryPy for mod_pythonThe recommended way to run CherryPy with mod_python is to use the mpcp module available from http://jamwt.com/. The following configuration example applies to Apache 2.0, mod_python 3, Python 2.4, and CherryPy 2.2. Here is how you configure Apache: ServerName 'cherrypy.example.com' PythonPath "['/path/to/project-root'] + sys.path' <Location "/"> SetHandler mod_python PythonHandler mpcp PythonOption cherrysetup control.main.root::mp_setup </Location> And here is sample code showing how to set up CherryPy for mod_python: import cherrypy class CherryApp: @cherrypy.expose def index(self, **kwargs): return 'Hello, World!' cherrypy.root = CherryApp() if __name__ == '__main__': # CP server testing with autoreload, etc cherrypy.config.update({'global' : {'server.socket_port' : 8000}}) cherrypy.server.start() def mp_setup(): """mod_python production setup""" cherrypy.config.update({'global' : {'server.environment' : 'production'}}) |