On 26/06/07, Ian Bicking <[EMAIL PROTECTED]> wrote: > For instance, doesn't atexit work fine for exiting? (Not in mod_python, > but I still don't know why it *shouldn't* work in mod_python.)
Exit functions registered by atexit don't work in mod_python for a few reasons. First off is that if you call Py_Finalize() then Python only calls exit functions on the main Python interpreter and does not do it on sub interpreters. Since code running under mod_python tends to run in sub interpreters, any atexit registered functions would never be called. The second problem is that calling Py_Finalize() was disabled in more recent versions of mod_python as it was causing lots of problems with strange Python exceptions and sometimes crashes occurring when triggered. In mod_wsgi I managed to work out what all the problems were and in mod_wsgi it will correctly call atexit registered functions registered in all sub interpreters as well as call Py_Finalize() to clean up other stuff related to any interpreters which were created. The changes in mod_wsgi even deal with changes made in Python 2.5 with how threads are killed off on killing a sub interpreter. Prior to 2.5 this was managed by an atexit registered function from threading module itself, but in 2.5 the Python C code itself triggers the cleanup actions for threads. Going back and fixing all this in mod_python is right down at the end of the reopened issue for Py_Finalize() causing problems in the first place. https://issues.apache.org/jira/browse/MODPYTHON-109 All the code in mod_python for Python initialisation and shutdown, plus interpreter management really needs to be completely rewritten as it is messy and still has bugs in there related to simplified GIL API, something which has again been fixed up in mod_wsgi. Graham _______________________________________________ Web-SIG mailing list Web-SIG@python.org Web SIG: http://www.python.org/sigs/web-sig Unsubscribe: http://mail.python.org/mailman/options/web-sig/archive%40mail-archive.com