[Web-SIG] A 'shutdown' function in WSGI

2012-02-20 Thread Tarek Ziadé
Hello I need to be able to call a function when the web application shuts down (SIGTERM/SIGINT) -- the use case is to stop a background thread. I am currently using signals because it seems to be the most clean way to do this. atexit is much trickier since you don't know when it's going to get ca

Re: [Web-SIG] SERVER_PORT and Unix sockets

2012-02-20 Thread Benoit Chesneau
On Mon, Jan 2, 2012 at 3:59 PM, Jonas H. wrote: > Hello everyone! > > What is SERVER_PORT supposed to be set to if the WSGI server is only bound > to a Unix socket? > > Some major Web servers (Gunicorn, CherryPy) set it to the empty string. > Intuitively I'd rather not set it at all. > > What do y

Re: [Web-SIG] A 'shutdown' function in WSGI

2012-02-20 Thread Eric Larson
CherryPy provides a bus that allows you to add events to the web server process. It is specified pretty clearly and CherryPy recently made it available as a standalone package, Magicbus (https://bitbucket.org/cherrypy/magicbus/overview). Specifically it allows you to send events on different si

Re: [Web-SIG] A 'shutdown' function in WSGI

2012-02-20 Thread Tarek Ziadé
On Mon, Feb 20, 2012 at 8:09 PM, Eric Larson wrote: > CherryPy provides a bus that allows you to add events to the web server > process. It is specified pretty clearly and CherryPy recently made it > available as a standalone package, Magicbus ( > https://bitbucket.org/cherrypy/magicbus/overview)

Re: [Web-SIG] A 'shutdown' function in WSGI

2012-02-20 Thread Tarek Ziadé
oops my examples were broken, should be: def hello_world_app(environ, start_response): status = '200 OK' # HTTP Status headers = [('Content-type', 'text/plain')] start_response(status, headers) return ["Hello World"] def shutdown(): # or maybe something else as an argument I don'

Re: [Web-SIG] A 'shutdown' function in WSGI

2012-02-20 Thread PJ Eby
The standard way to do this would be to define an "optional server extension" API supplied in the environ; for example, a 'x-wsgiorg.register_shutdown' function. The wsgi.org wiki used to be the place to propose these sorts of things for standardization, but it appears to no longer be a wiki, so t

Re: [Web-SIG] A 'shutdown' function in WSGI

2012-02-20 Thread Chris McDonough
On Mon, 2012-02-20 at 17:39 -0500, PJ Eby wrote: > The standard way to do this would be to define an "optional server > extension" API supplied in the environ; for example, a > 'x-wsgiorg.register_shutdown' function. Unlikely, AFACIT, as shutdown may happen when no request is active. Even if this

Re: [Web-SIG] A 'shutdown' function in WSGI

2012-02-20 Thread Simon Sapin
Le 21/02/2012 01:18, Chris McDonough a écrit : On Mon, 2012-02-20 at 17:39 -0500, PJ Eby wrote: > The standard way to do this would be to define an "optional server > extension" API supplied in the environ; for example, a > 'x-wsgiorg.register_shutdown' function. Unlikely, AFACIT, as shutdow

Re: [Web-SIG] A 'shutdown' function in WSGI

2012-02-20 Thread Graham Dumpleton
On 21 February 2012 12:03, Simon Sapin wrote: > Le 21/02/2012 01:18, Chris McDonough a écrit : > >> On Mon, 2012-02-20 at 17:39 -0500, PJ Eby wrote: >>> >>> >  The standard way to do this would be to define an "optional server >>> >  extension" API supplied in the environ; for example, a >>> >  'x

Re: [Web-SIG] A 'shutdown' function in WSGI

2012-02-20 Thread PJ Eby
2012/2/20 Chris McDonough > On Mon, 2012-02-20 at 17:39 -0500, PJ Eby wrote: > > The standard way to do this would be to define an "optional server > > extension" API supplied in the environ; for example, a > > 'x-wsgiorg.register_shutdown' function. > > Unlikely, AFACIT, as shutdown may happen w

Re: [Web-SIG] A 'shutdown' function in WSGI

2012-02-20 Thread Chris McDonough
On Mon, 2012-02-20 at 20:54 -0500, PJ Eby wrote: > 2012/2/20 Chris McDonough > On Mon, 2012-02-20 at 17:39 -0500, PJ Eby wrote: > > The standard way to do this would be to define an "optional > server > > extension" API supplied in the environ; for example, a >

Re: [Web-SIG] A 'shutdown' function in WSGI

2012-02-20 Thread Tarek Ziadé
2012/2/21 Chris McDonough > On Mon, 2012-02-20 at 20:54 -0500, PJ Eby wrote: > > 2012/2/20 Chris McDonough > > On Mon, 2012-02-20 at 17:39 -0500, PJ Eby wrote: > > > The standard way to do this would be to define an "optional > > server > > > extension" API suppli

Re: [Web-SIG] A 'shutdown' function in WSGI

2012-02-20 Thread Tarek Ziadé
On Tue, Feb 21, 2012 at 2:39 AM, Graham Dumpleton < graham.dumple...@gmail.com> wrote: > ... > Overall the best chance of being able to do anything is relying on atexit. > > You are though at the mercy of the WSGI hosting mechanism shutting > down the process and so the interpreter, in an orderly

Re: [Web-SIG] A 'shutdown' function in WSGI

2012-02-20 Thread Simon Sapin
Le 21/02/2012 08:47, Tarek Ziadé a écrit : Yes, I also think shutting down the server is completely orthogonal to requests. If the shutdown callback is next to the application and not registered in a request, why not also have the symmetric "server start up" callback that would not wait for a