[Web-SIG] A 'shutdown' function in WSGI
ziade.tarek at gmail.com
Tue Feb 21 14:46:21 CET 2012
On Tue, Feb 21, 2012 at 1:43 PM, Antoine Pitrou <solipsis at pitrou.net> wrote:
> Tarek Ziadé <ziade.tarek at ...> writes:
> > On Tue, Feb 21, 2012 at 10:24 AM, Graham Dumpleton
> <graham.dumpleton at gmail.com> wrote:
> > ...
> > > But I don't think you can guarantee that everything is still up in
> memory by
> > > the time atexit gets called,
> > > so you can't really call cleanup code there.
> > The only thing which is done prior to atexit callbacks being called is
> > waiting on threads which weren't marked as daemonised.
> > which can lead to completely lock the shutdown if a lib or the program
> has a
> > thread with a loop that waits for a condition.which it is not the case
> > signals, since you get a chance to properly stop everything beforehand.
> That's a buggy lib or program. This has nothing to do with WSGI really.
No, that has to do with : please let me clean my program before you try to
kill it because I can't use signals :)
> snippet Graham showed is run at any interpreter shutdown, even when you
> run "python" in your shell.
here's a very simple demo: http://tarek.pastebin.mozilla.org/1489505
Run it with plain python, and try to ctrl-C it. You won't reach atexit and
will get locked.
(here: python 2.7 / mac os)
If you use signals instead of atexit, you'll have it working.
And this pattern (a thread in the background) is pretty common -- unless I
am missing something here
> Web-SIG mailing list
> Web-SIG at python.org
> Web SIG: http://www.python.org/sigs/web-sig
Tarek Ziadé | http://ziade.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Web-SIG