Package wsgitools :: Package scgi :: Module forkpool :: Class SCGIServer
[hide private]
[frames] | no frames]

Class SCGIServer

source code


Usage: create an SCGIServer object and invoke the run method which will then turn this process into an scgi server.

Nested Classes [hide private]
  WorkerState
state: 0 means idle and 1 means working.
Instance Methods [hide private]
 
__init__(self, wsgiapp, port, interface='localhost', error=<epydoc.docintrospecter._DevNull object>, minworkers=2, maxworkers=32, maxrequests=1000, config={}, reusesocket=None, cpulimit=None, timelimit=None)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
enable_sighandler(self, sig=15)
Changes the signal handler for the given signal to terminate the run() loop.
source code
 
run(self)
Serve the wsgi application.
source code
 
killworkers(self, sig=15)
Kills all worker children.
source code
 
shutdownhandler(self, sig=None, stackframe=None)
Signal handler function for stopping the run() loop.
source code
 
sigxcpuhandler(self, sig=None, stackframe=None)
Signal hanlder function for the SIGXCUP signal.
source code
 
spawnworker(self)
internal! spawns a single worker
source code
 
work(self, worksock)
internal! serves maxrequests times
source code
 
process(self, con)
internal! processes a single request on the connection con.
source code

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

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, wsgiapp, port, interface='localhost', error=<epydoc.docintrospecter._DevNull object>, minworkers=2, maxworkers=32, maxrequests=1000, config={}, reusesocket=None, cpulimit=None, timelimit=None)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Parameters:
  • wsgiapp - is the WSGI application to be run.
  • port (int) - is the tcp port to listen on
  • interface (str) - is the interface to bind to (default: "localhost")
  • error - is a file-like object beeing passed as wsgi.errors in environ
  • minworkers (int) - is the number of worker processes to spawn
  • maxworkers (int) - is the maximum number of workers that can be spawned on demand
  • maxrequests (int) - is the number of requests a worker processes before dying
  • config ({}) - the environ dictionary is updated using these values for each request.
  • reusesocket (None or socket.socket) - If a socket is passed, do not create a socket. Instead use given socket as listen socket. The passed socket must be set up for accepting tcp connections (i.e. AF_INET, SOCK_STREAM with bind and listen called).
  • cpulimit ((int, int)) - a pair of soft and hard cpu time limit in seconds. This limit is installed for each worker using RLIMIT_CPU if resource limits are available to this platform. After reaching the soft limit workers will continue to process the current request and then cleanly terminate.
  • timelimit (int) - The maximum number of wall clock seconds processing a request should take. If this is specified, an alarm timer is installed and the default action is to kill the worker.
Overrides: object.__init__

enable_sighandler(self, sig=15)

source code 

Changes the signal handler for the given signal to terminate the run() loop.

Parameters:
  • sig - is the signal to handle
Returns:
self

killworkers(self, sig=15)

source code 

Kills all worker children.

Parameters:
  • sig - is the signal used to kill the children

shutdownhandler(self, sig=None, stackframe=None)

source code 

Signal handler function for stopping the run() loop. It works by setting a variable that run() evaluates in each loop. As a signal interrupts accept the loop is terminated, the accepting socket is closed and the workers are killed.

Parameters:
  • sig - ignored for usage with signal.signal
  • stackframe - ignored for usage with signal.signal

sigxcpuhandler(self, sig=None, stackframe=None)

source code 

Signal hanlder function for the SIGXCUP signal. It is sent to a worker when the soft RLIMIT_CPU is crossed.

Parameters:
  • sig - ignored for usage with signal.signal
  • stackframe - ignored for usage with signal.signal

work(self, worksock)

source code 

internal! serves maxrequests times

Raises:
  • socket.error