Issue #537 resolved

Support for listening on multiple ports

Anonymous created an issue

CherryPy does not provide a simple mechanism for litening on multiple ports, as cherrypy.config's state is not thread-local. The mailing list thread leading to the filing of this bug is below.

Charles Duffy wrote: {{{ Quick question: Is there an easy way to make a CherryPy- based application bind to multiple ports? It's obviously straightforward if going through Apache, but I'm thinking about this in the context of a much smaller, self-contained package. }}}

James Mills wrote: {{{ Could you not run two threads ? (Configured on different ports) }}}

Charles Duffy: {{{ Err... how do I do that? Is cherrypy.config's state thread-local? }}}

Robert Brewer: {{{ The "server.socket_port" isn't--it's read once when starting the server. You'd have to start your own http server by hand (_cpwsgiserver has no dependency on CherryPy, so it should mostly be a matter of duplicating the logic of _cpwsgi.WSGIServer.init).

I'd appreciate a ticket on this for CherryPy 3 at least--go ahead and assign it to me (fumanchu). }}}

Reported by

Comments (3)

  1. Robert Brewer

    Fixed in [1217].

    I didn't think it was worth the effort to make new config entries for this use-case, so the normal cherrypy.server.start hasn't changed. But cherrypy.server may now manage multiple HTTP servers through programmatic means; just set cherrypy.server.httpservers[httpserver instance] = (host, port) if you need more than one.

  2. Robert Brewer

    Bah. Keeping the old start() method really screws up code (like test_states) that tried to start after a stop. So in [1219] I just bit the bullet and renamed server.start to server.quickstart, and server.start_all to server.start.

  3. Log in to comment