The Seal web server is essentially a controller for a ServerDaemon instance, which is a specialization of the standard ThreadingHTTPServer (from the standard server module). The server daemon runs in a separate thread, so that it does not monopolize the main thread.
When the server daemon receives an HTTP request, it starts a thread for that request and instantiates an HTTPRequestHandler in the new thread. It is possible for the daemon to receive multiple requests in rapid sequence, thus that multiple request-handler threads run simultaneously.
The HTTP request handler is a specialization of the standard class BaseHTTPRequestHandler (from the standard server module). BaseHTTPRequestHandler has a large number of members and methods, so to avoid any risk of adverse interactions, our specialization hands off all the actual work to a separate class called ApplicationCaller. The ApplicationCaller is instantiated with a back pointer to the HTTP request handler, then its run() method is called.
User control of the server and application caller is via a configuration dict, which is passed first to the Server, and thence to the ServerDaemon. The request handler is created within standard library code, but the standard code provides it with a backlink to the server daemon. Hence the application caller's backlink to the handler gives it indirect access to the server daemon, and thence to the configuration dict.
The application caller creates a Request, fetches the application function from the configuration dict, passes the request to the application function and receives a Response in return. Then it renders the response in HTTP format on the handler's output stream, which is connected to the client.
The Server class is a wrapper for the "real" server, which is a Python web server. The web server that is used combines WSGIServer (from module wsgiref.simple_server) with ThreadingMixIn (from module socketserver).
The Server constructor takes a single argument, a WsgiApp. It should be used in a with-statement. The __enter__() method calls start(), which runs _start_server() in a separate thread. The start() function waits, and does not return, until the started flag has been set.
The _start_server() method instantiates the real server, sets the started flag, and immediately calls the web server's serve_forever() method. In other words, the start() method returns once the real-server thread has started up and the real server has been created.
The Server's __exit__() method dispatches to stop(), which calls the real server's shutdown() method to request shutdown. Then it waits for the stopped flag to be set before returning.
When the real server shuts down, the subordinate thread function _start_server() receives control again, and it sets the stopped flag. Then it returns, terminating the subordinate thread.