The standard way to do this would be to define an &quot;optional server extension&quot; API supplied in the environ; for example, a &#39;x-wsgiorg.register_shutdown&#39; function.  The <a href="http://wsgi.org">wsgi.org</a> wiki used to be the place to propose these sorts of things for standardization, but it appears to no longer be a wiki, so the mailing list is probably a good place to discuss such a proposal.<br>
<br><div class="gmail_quote">On Mon, Feb 20, 2012 at 2:30 PM, Tarek Ziadé <span dir="ltr">&lt;<a href="mailto:ziade.tarek@gmail.com">ziade.tarek@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
oops my examples were broken, should be:<br><span></span><br><pre><div class="im"><span>def</span> <span>hello_world_app</span><span>(</span><span>environ</span><span>,</span> <span>start_response</span><span>):</span>
    <span>status</span> <span>=</span> <span>&#39;200 OK&#39;</span> <span># HTTP Status</span>
    <span>headers</span> <span>=</span> <span>[(</span><span>&#39;Content-type&#39;</span><span>,</span> <span>&#39;text/plain&#39;</span><span>)]</span> 
    <span>start_response</span><span>(</span><span>status</span><span>,</span> <span>headers</span><span>)</span>
    <span>return</span> <span>[</span><span>&quot;Hello World&quot;</span><span>]</span><span></span>
<br></div><div class="im">def shutdown():   # or maybe something else as an argument I don&#39;t know<br>   do_some_cleanup()<br><br></div></pre><br>and:<br><br>$ gunicorn myapp:<span>hello_world_app</span>
 myapp:shutdown<br><br><br><br>Cheers<br><font color="#888888">Tarek<br>
</font><br>_______________________________________________<br>
Web-SIG mailing list<br>
<a href="mailto:Web-SIG@python.org">Web-SIG@python.org</a><br>
Web SIG: <a href="http://www.python.org/sigs/web-sig" target="_blank">http://www.python.org/sigs/web-sig</a><br>
Unsubscribe: <a href="http://mail.python.org/mailman/options/web-sig/pje%40telecommunity.com" target="_blank">http://mail.python.org/mailman/options/web-sig/pje%40telecommunity.com</a><br>
<br></blockquote></div><br>