[Web-SIG] A 'shutdown' function in WSGI
ziade.tarek at gmail.com
Mon Feb 20 17:03:49 CET 2012
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 called and you might try to call objects that were garbage collected
unless you hack something to keep references alive.
But signals are also tricky beasts since you may compete with other code
that are listening to them. For instance mod_wsgi don't like apps that have
Anyways, the bottom line is that the cleanest way to do this -- as per
Chris McDonough idea, would be to introduce in the WSGI protocol a
"shutdown" function the servers would be obligated to call before exiting.
I am not sure yet about its arguments, maybe a signum + frame or simply an
But how do you like the idea ? That would solve for me the problem of
having to deal differently here depending on if I am called with mod_wsgi
or gunicorn or xxx
Tarek Ziadé | http://ziade.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Web-SIG