pyrtma.web_manager.TCPServer
- class TCPServer(server_address, RequestHandlerClass, bind_and_activate=True)[source]
Bases:
BaseServer
Base class for various socket-based server classes.
Defaults to synchronous IP stream (i.e., TCP).
Methods for the caller:
__init__(server_address, RequestHandlerClass, bind_and_activate=True)
serve_forever(poll_interval=0.5)
shutdown()
handle_request() # if you don’t use serve_forever()
fileno() -> int # for selector
Methods that may be overridden:
server_bind()
server_activate()
get_request() -> request, client_address
handle_timeout()
verify_request(request, client_address)
process_request(request, client_address)
shutdown_request(request)
close_request(request)
handle_error()
Methods for derived classes:
finish_request(request, client_address)
Class variables that may be overridden by derived classes or instances:
timeout
address_family
socket_type
request_queue_size (only for stream sockets)
allow_reuse_address
Instance variables:
server_address
RequestHandlerClass
socket
Constructor. May be extended, do not override.
Methods
Called to clean up an individual request.
Return socket file number.
Finish one request by instantiating RequestHandlerClass.
Get the request and client address from the socket.
Handle an error gracefully.
Handle one request, possibly blocking.
Called if no new request arrives within self.timeout.
Call finish_request.
Handle one request at a time until shutdown.
Called by constructor to activate the server.
Called by constructor to bind the socket.
Called to clean-up the server.
Called by the serve_forever() loop.
Stops the serve_forever loop.
Called to shutdown and close an individual request.
Verify the request.
Attributes
address_family
allow_reuse_address
request_queue_size
socket_type
timeout
- finish_request(request, client_address)
Finish one request by instantiating RequestHandlerClass.
- handle_error(request, client_address)
Handle an error gracefully. May be overridden.
The default is to print a traceback and continue.
- handle_request()
Handle one request, possibly blocking.
Respects self.timeout.
- handle_timeout()
Called if no new request arrives within self.timeout.
Overridden by ForkingMixIn.
- process_request(request, client_address)
Call finish_request.
Overridden by ForkingMixIn and ThreadingMixIn.
- serve_forever(poll_interval=0.5)
Handle one request at a time until shutdown.
Polls for shutdown every poll_interval seconds. Ignores self.timeout. If you need to do periodic tasks, do them in another thread.
- service_actions()
Called by the serve_forever() loop.
May be overridden by a subclass / Mixin to implement any code that needs to be run during the loop.
- shutdown()
Stops the serve_forever loop.
Blocks until the loop has finished. This must be called while serve_forever() is running in another thread, or it will deadlock.
- verify_request(request, client_address)
Verify the request. May be overridden.
Return True if we should proceed with this request.