Package cherrypy :: Module _cpserver :: Class Server
[hide private]
[frames] | no frames]

Class Server

source code

object --+
         |
        Server

Manager for a set of HTTP servers.

This is both a container and controller for "HTTP server" objects,
which are kept in Server.httpservers, a dictionary of the form:
{httpserver: bind_addr} where 'bind_addr' is usually a (host, port)
tuple.

Most often, you will only be starting a single HTTP server. In this
common case, you can set attributes (like socket_host and socket_port)
on *this* object (which is probably cherrypy.server), and call
quickstart. For example:

    cherrypy.server.socket_port = 80
    cherrypy.server.quickstart()

But if you need to start more than one HTTP server (to serve on multiple
ports, or protocols, etc.), you can manually register each one and then
control them all through this object:

    s1 = MyWSGIServer(host='', port=80)
    s2 = another.HTTPServer(host='localhost', SSL=True)
    cherrypy.server.httpservers = {s1: ('', 80), s2: ('localhost', 443)}
    # Note we do not use quickstart when we define our own httpservers
    cherrypy.server.start()

Whether you use quickstart(), or define your own httpserver entries and
use start(), you'll find that the start, wait, restart, and stop methods
work the same way, controlling all registered httpserver objects at once.



Instance Methods [hide private]
 
__init__(self)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
source code
 
quickstart(self, server=None)
Start from defaults.
source code
 
httpserver_from_self(self, httpserver=None)
Return a (httpserver, bind_addr) pair based on self attributes.
source code
 
start(self)
Start all registered HTTP servers.
source code
 
_start_http(self, httpserver)
Start the given httpserver in a new thread.
source code
 
_start_http_thread(self, httpserver)
HTTP servers MUST be started in new threads, so that the main thread persists to receive KeyboardInterrupt's.
source code
 
wait(self, httpserver=None)
Wait until the HTTP server is ready to receive requests.
source code
 
stop(self)
Stop all HTTP servers.
source code
 
restart(self)
Restart all HTTP servers.
source code
 
base(self)
Return the base (scheme://host) for this server manager.
source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Class Variables [hide private]
  socket_port = 8080
  socket_host = ''
  socket_file = ''
  socket_queue_size = 5
  socket_timeout = 10
  protocol_version = 'HTTP/1.1'
  reverse_dns = False
  thread_pool = 10
  max_request_header_size = 512000
  max_request_body_size = 104857600
  instance = None
  ssl_certificate = None
  ssl_private_key = None
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self)
(Constructor)

source code 
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
Overrides: object.__init__
(inherited documentation)

quickstart(self, server=None)

source code 

Start from defaults. MUST be called from the main thread.

This function works like CherryPy 2's server.start(). It loads and starts an httpserver based on the given server object (if provided) and attributes of self.

_start_http_thread(self, httpserver)

source code 
HTTP servers MUST be started in new threads, so that the main thread persists to receive KeyboardInterrupt's. If an exception is raised in the httpserver's thread then it's trapped here, and the httpserver(s) and engine are shut down.

wait(self, httpserver=None)

source code 

Wait until the HTTP server is ready to receive requests.

If no httpserver is specified, wait for all registered httpservers.