Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Server object

Properties

  • socket_port: (default 8080)
  • socket_host: (default '127.0.0.1') The hostname or IP address on which to listen for connections. Host values may be any IPv4 or IPv6 address, or any valid hostname. The string 'localhost' is a synonym for '127.0.0.1' (or '::1', if your hosts file prefers IPv6). The string '0.0.0.0' is a special IPv4 entry meaning "any active interface" (INADDR_ANY), and '::' is the similar IN6ADDR_ANY for IPv6. The empty string or None are not allowed.
  • socket_file: (default "") Set this to a non-blank value to use UNIX domain sockets instead of TCP sockets.
  • socket_queue_size: (default 5) The 'backlog' argument to socket.listen(); specifies the maximum number of queued connections.
  • socket_timeout: (default 10) The number of seconds which the server will wait for data from the client on the socket. This governs both the time to first byte and time between requests on a persistent connection. If the timeout expires, the server will close the socket.
  • shutdown_timeout: (default 5) The number of seconds the server will wait for worker threads to finish when shutting down.
  • protocol_version: (default 'HTTP/1.1') The version at which the server will announce itself in HTTP responses.
  • reverse_dns: Not currently used.
  • thread_pool: (default 10) The number of worker threads the server will start to read requests and write responses.
  • thread_pool_max: (default -1) The maximum number of worker threads for resizable thread pools. Not currently used.
  • max_request_header_size: (default 500K) The maximum size, in bytes, of an HTTP request header block. The server will return "413 Request Entity Too Large" if a request has a header block larger than this number.
  • max_request_body_size: (default 100M) The maximum size, in bytes, of an HTTP request body. The server will return "413 Request Entity Too Large" if a request has an entity body larger than this number.
  • ssl_certificate, ssl_private_key: (both default to None). If provided, the server will run HTTPS (SSL) instead of HTTP. Both values should be valid absolute filenames. Requires pyOpenSSL.
  • nodelay: if True (the default since 3.1), the listening socket will have the TCP_NODELAY option set, which disables the Nagle algorithm and can improve performance.

Methods

subscribe()

Registers the server to start/stop when cherrypy.engine starts/stops.

unsubscribe()

Unregister the server with cherrypy.engine. Call this when you want to run HTTP servers other than the default.

wait(httpserver=None)

(3.0+) Wait until the given HTTP server is ready to receive requests. If no httpserver is specified, wait for all registered httpservers. You should only call this yourself if you're doing crazy test fixtures; otherwise, let cherrypy.engine call it for you.

start

Start the HTTP server (3.0: all HTTP servers). You should not call this yourself; let cherrypy.engine do it for you.

stop

Stop the HTTP server (3.0: all HTTP servers). Well, "suspend" might be a better term - this doesn't terminate the process. You should not call this yourself; let cherrypy.engine do it for you.

restart

Restart the HTTP server (3.0: all HTTP servers).

base

Return the base (scheme://host) for the default HTTP server.

Older versions

3.0

In CherryPy 3.0, cherrypy.server needed to be started independently of cherrypy.engine (it didn't have subscribe/unsubscribe). So you would need to write:

    tree.mount(root, script_name, config)
    server.quickstart()
    engine.start()

In 3.1, you can omit server.quickstart().

2.2

replace thiswith this
server.quickstartserver.start(init_only=True)

In CherryPy 2, cherrypy.server was a subclass of cherrypy.engine, and therefore had the following additional attributes:

Hosted by WebFaction

Log in as guest/cpguest to create tickets