[issue6531] atexit_callfuncs() crashing within Py_Finalize() when using multiple interpreters.

Antoine Pitrou report at bugs.python.org
Wed Jan 18 11:56:49 CET 2012


Antoine Pitrou <pitrou at free.fr> added the comment:

> That said, for mod_wsgi I have extended sub interpreter destruction so
> that atexit callbacks registered in sub interpreters are called. For
> mod_wsgi though, sub interpreters are only destroyed on process
> shutdown. For the general case, a sub interpreter could be destroyed
> at any time during the life of the process. If one called atexit
> callbacks on such sub interpreter destruction, it notionally changes
> the meaning of atexit, which is in process exit and not really sub
> interpreter exit.

Well the atexit docs say "Functions thus registered are automatically
executed upon normal interpreter termination".

My reasoning is:
- atexit functions are already called at interpreter destruction (*),
not at process shutdown. If you call Py_Initialize and Py_Finalize
several times in a row, you will have several atexit calls.

- registering a function in an interpreter and calling it in another is
undefined and potentially dangerous. That function can for example refer
to global objects which are different from the calling interpreter's
global objects. These objects or their internal structures could have
become invalid when the sub-interpreter was shut down.

I expect uses of sub-interpreters to be quite rare apart from mod_wsgi,
so following mod_wsgi makes sense IMO.

(*) note atexit functions are even called *before* module globals are
garbage collected. It's quite early in the cleanup phase.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6531>
_______________________________________


More information about the Python-bugs-list mailing list