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