Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Cherrypy Port and restart web server

Is there a way in python to change the port that cherrypy is using and force the web server (not apache, cherrypy) to restart?

like image 216
williamtroup Avatar asked Aug 31 '11 09:08

williamtroup


2 Answers

If you don't want to replace the whole process (which is what cherrypy.engine.restart() does), you could do:

import cherrypy
cherrypy.engine.stop()
cherrypy.server.httpserver = None
cherrypy.config.update({'server.socket_port': 8099})
cherrypy.engine.start()

Setting httpserver to None is needed or the cherrypy.engine.start() call will just reuse the host/port it already has rather than picking up the changed configuration. I'm not sure if that is inappropriately taking advantage of an implementation detail, though.

like image 60
Eric Smith Avatar answered Oct 31 '22 11:10

Eric Smith


Have a look at cherrypy.process.servers. You can try something like this:

import cherrypy
cherrypy.config.update({'server.socket_port': 8099})
cherrypy.engine.restart()
like image 29
Reto Aebersold Avatar answered Oct 31 '22 11:10

Reto Aebersold