Hello All,
I am quite new to cherrypy and mod_python. I have set up my
application to run behind apache 2 with mod_python.
I am using cherrypy 3.1.0, apache 2, and mod_python 3.3.1
Here is my configuration in httpd.conf
<VirtualHost *:80>
ServerName
myapp.com
ServerAlias
www.myapp.com
DocumentRoot /var/www/html
<Location "/">
PythonPath "sys.path+['/var/www/html']"
SetHandler python-program
PythonHandler cherrypy._cpmodpy::handler
PythonOption cherrypy.setup cpdeploy::serverless
PythonDebug On
</Location>
LogLevel warn
ErrorLog /var/www/html/dummy-host.example.com-error_log
CustomLog /var/www/html/dummy-host.example.com-access_log combined
</VirtualHost>
And here is the code of my application : cpdeploy.py
--------------------------------------------------------------------------------------------------------------------------------------------
#!python
"""Deployment script for CherryPy + Apache (or other front-end)."""
import os
import cherrypy
class Track(object):
def index(self):
return "Track index"
index.exposed = True
def test(self):
return "Track::test"
test.exposed = True
class Album(object):
def index(self):
return "Album index"
index.exposed = True
def test(self):
return "Album::test"
test.exposed = True
class Root(object):
album = Album()
track = Track()
def index(self):
return "Hello cherrypy with mod_python"
index.exposed = True
def test(self):
return "This is a test method"
test.exposed = True
root = Root()
def serverless():
"""Start with no server (for mod_python or other WSGI HTTP
servers).
You can also use this mode interactively:
>>> import cpdeploy
>>> cpdeploy.serverless()
"""
# Set up site-wide config. Do this first so that,
# if something goes wrong, we get a log.
cherrypy.config.update({
'log.screen': False,
'log.error_file': '/tmp/site.log',
'environment': 'production',
'request.show_tracebacks': False,
# Turn off signal handlers when CP does not control the OS
process
'engine.SIGTERM': None,
'engine.SIGHUP': None
})
cherrypy.tree.mount(root)
try:
cherrypy.engine.start()
except:
cherrypy.log(traceback=True)
raise
def serve():
"""Start with the builtin server."""
# Set up site-wide config. Do this first so that,
# if something goes wrong, we get a log.
cherrypy.config.update({
'log.screen': True,
'log.error_file': '/tmp/site.log',
'environment': 'production',
})
cherrypy.tree.mount(root)
#cherrypy.server.quickstart()
cherrypy.engine.start()
if __name__ == "__main__":
serve()
---------------------------------------------------------------------------------------------------------------------------------------------------
Now the problem is, it runs fine with very first request and on the
second request I get
Unrecoverable error in the server error. and here is the traceback
which is found in /tmp/site.log file.
File "/usr/lib/python2.4/site-packages/cherrypy/_cpmodpy.py",
line 139, in handler
setup(req)
File "/usr/lib/python2.4/site-packages/cherrypy/_cpmodpy.py",
line 84, in setup
func()
File "/var/www/html/cpdeploy.py", line 65, in serverless
cherrypy.engine.start()
File "/usr/lib/python2.4/site-packages/cherrypy/process/
wspbus.py", line 180, in start
self.publish('start')
File "/usr/lib/python2.4/site-packages/cherrypy/process/
wspbus.py", line 147, in publish
output.append(listener(*args, **kwargs))
File "/usr/lib/python2.4/site-packages/cherrypy/_cpserver.py",
line 89, in start
ServerAdapter.start(self)
File "/usr/lib/python2.4/site-packages/cherrypy/process/
servers.py", line 53, in start
wait_for_free_port(*self.bind_addr)
File "/usr/lib/python2.4/site-packages/cherrypy/process/
servers.py", line 209, in wait_for_free_port
raise IOError("Port %r not free on %r" % (port, host))
IOError: Port 8080 not free on '127.0.0.1'
-------------------------------------------------------------------------------------------------------------------------------------------
I am stuck on this for a while. I would really appreciate your help.
Thank you,
Sanket