webapp_server: Server side for Chimera 2 web application¶
Communicate with WSGI app to process web app requests and return results. Request and result formats are described in Wire Protocol.
The Server
class is an abstract base class that should
be subclassed to provide custom functionality. The intended
usage pattern is:
s = Server()
for tag, handler in tag_handler_list:
s.register_handler(tag, handler)
s.run()
Handlers are called with a single argument: the value field of the request. Return values from handlers should be a dictionary with the same keys as the JSON return object described in Wire Protocol, with the exception that the id field should _not_ be assigned.
-
class
Server
¶ Bases:
object
Class for communicating with WSGI app and processing requests.
This class establishes communications with WSGI app using multiprocessing Connection objects. JSON requests are parsed and dispatched to registered handlers; return value from handlers are packaged into JSON and sent back to the WSGI app. Requests are accepted on standard input and results are returned on standard output.
Command line arguments are parsed and saved in the following attributes:
session_file: name of file where session data may be found and/or saved
-
deregister_handler
(tag, handler)¶ Deregister request handler.
-
register_handler
(tag, handler)¶ Register handler to process request and return result.
For requests with the given tag, handler will be called with the corresponding value. Multiple handlers may be registered for a single tag type.
-
run
()¶ Enter event loop to process requests.
-
set_log
(log)¶ Set file-like object for logging events and errors.
-
terminate
()¶ Terminate event loop started by
run()
.This is usually called by one of the handlers to exit the currently active run event loop.
-