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=sys.stderr, minworkers=2, maxworkers=32, maxrequests=1000, config={}) 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
 
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
Method Details [hide private]

__init__(self, wsgiapp, port, interface='localhost', error=sys.stderr, minworkers=2, maxworkers=32, maxrequests=1000, config={})
(Constructor)

source code 
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.error 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.

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

work(self, worksock)

source code 

internal! serves maxrequests times

Raises:
  • socket.error