flup.server.scgi_fork - scgi - an SCGI/WSGI gateway (forking)

scgi - an SCGI/WSGI gateway.

copyright:

Copyright (c) 2005, 2006 Allan Saddi <allan@saddi.com> All rights reserved.

license:

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

For more information about SCGI and mod_scgi for Apache1/Apache2, see http://www.mems-exchange.org/software/scgi/.

For more information about the Web Server Gateway Interface, see http://www.python.org/peps/pep-0333.html.

Example usage:

1
2
3
4
5
6
#!/usr/bin/env python
import sys
from myapplication import app # Assume app is your WSGI application object
from scgi import WSGIServer
ret = WSGIServer(app).run()
sys.exit(ret and 42 or 0)

See the documentation for WSGIServer for more information.

About the bit of logic at the end: Upon receiving SIGHUP, the python script will exit with status code 42. This can be used by a wrapper script to determine if the python script should be re-run. When a SIGINT or SIGTERM is received, the script exits with status code 0, possibly indicating a normal exit.

Example wrapper script:

1
2
3
4
5
6
#!/bin/sh
STATUS=42
while test $STATUS -eq 42; do
  python "$@" that_script_above.py
  STATUS=$?
done
class flup.server.scgi_fork.WSGIServer(application, scriptName=<class 'flup.server.NoDefault'>, environ=None, bindAddress=('localhost', 4000), umask=None, allowedServers=None, loggingLevel=20, debug=False, timeout=None, **kw)

SCGI/WSGI server. For information about SCGI (Simple Common Gateway Interface), see http://www.mems-exchange.org/software/scgi/.

This server is similar to SWAP http://www.idyll.org/~t/www-tools/wsgi/, another SCGI/WSGI server.

It differs from SWAP in that it isn’t based on scgi.scgi_server and therefore, it allows me to implement concurrency using threads. (Also, this server was written from scratch and really has no other depedencies.) Which server to use really boils down to whether you want multithreading or forking. (But as an aside, I’ve found scgi.scgi_server’s implementation of preforking to be quite superior. So if your application really doesn’t mind running in multiple processes, go use SWAP. ;)

error(request)

Override to provide custom error handling. Ideally, however, all errors should be caught at the application level.

handler(request)

WSGI handler. Sets up WSGI environment, calls the application, and sends the application’s response.

requestClass

alias of Request

run()

Main loop. Call this after instantiating WSGIServer. SIGHUP, SIGINT, SIGQUIT, SIGTERM cause it to cleanup and return. (If a SIGHUP is caught, this method returns True. Returns False otherwise.)

Previous topic

flup.server.scgi - scgi - an SCGI/WSGI gateway (threaded)

Next topic

flup.server.paste_factory

This Page