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

Benoit Chesneau bchesneau at gmail.com
Tue Feb 21 10:38:16 CET 2012


On Tue, Feb 21, 2012 at 10:35 AM, Sylvain Hellegouarch <sh at defuze.org> wrote:
>
>
> On Tue, Feb 21, 2012 at 10:31 AM, Graham Dumpleton
> <graham.dumpleton at gmail.com> wrote:
>>
>> On 21 February 2012 20:26, Simon Sapin <simon.sapin at exyr.org> wrote:
>> > Le 21/02/2012 09:23, Tarek Ziadé a écrit :
>> >
>> >>    Instead of having to provide two or three objects separately to a
>> >>    server, how about making the callbacks attributes of the application
>> >>    callable?
>> >>
>> >>
>> >> can you show us an example ?
>> >
>> >
>> > Proposal:
>> >
>> > Function-based:
>> >
>> >    def startup():
>> >        return open_resource(something)
>> >
>> >    def shutdown(resource):
>> >        resource.close()
>> >
>> >    def application(environ, start_response):
>> >        # ...
>> >        return response_body
>> >
>> >    application.startup = startup
>> >    application.shutdown = shutdown
>> >
>> > Class-based:
>> >
>> >    class App(object):
>> >        def startup(self):
>> >            return open_resource(something)
>> >
>> >        def shutdown(self, resource):
>> >            resource.close()
>> >
>> >        def __call__(self, environ, start_response):
>> >            # ...
>> >            return response_body
>> >
>> >    application = App()
>> >
>> > The return value of startup() can be any python object and is opaque to
>> > the
>> > server. It is passed as-is to shutdown()
>> >
>> > startup() could take more parameters. Maybe the application (though can
>> > we
>> > already have it as self for class-based or in a closure for
>> > function-based)
>>
>> You do realise you are just reinventing context managers?
>>
>> With this 'application' do requests.
>>
>> But then it was sort of suggested that was a bit too radical idea when
>> I have mentioned viewing it that way before. :-(
>>
>
> One might wonder if having access to process management should be part of
> WSGI in the first place.
>

that's the thing. This is no more a gateway. Like I said in my
previous post, maybe having another spec describing a web app package
would do the trick?

- benoît


More information about the Web-SIG mailing list