[issue4200] atexit module not safe in Python 3.0 with multiple interpreters

Graham Dumpleton report at bugs.python.org
Sat Oct 25 04:40:44 CEST 2008


Graham Dumpleton <Graham.Dumpleton at gmail.com> added the comment:

I wouldn't be concerned about mod_python as likelihood that it will be ported is 
very low and even if it was it would be a long long way in the future. There is too 
much in mod_python itself unrelated to Python 3.0 that needs to be fixed before a 
port to Python 3.0 should be considered.

As to mod_wsgi, I can work around it in the short term by installing an 'atexit' 
module replacement in sub interpreters and avoid the problem.

As to a solution, yes, using PyInterpreterState would seem the most logical place, 
however there is a lot more to it than that.

Prior to Python 3.0, any callbacks registered with atexit module in sub interpreters 
weren't called anyway. This is because Py_EndInterpreter() didn't trigger them, nor 
did Py_Finalize(). The latter is in Python 3.0 at the moment, but as pointed out 
that is a problem in itself.

So, although one may register sub interpreter atexit callbacks against PyInterpreterState, what would be done with them. A decision would need to be made 
as to whether Py_EndInterpreter() should trigger them, or whether the status quo be 
maintained and nothing done with them.

In the short term, ie., for Python 3.0.0, the simplest thing to do may be to have 
functions of atexit module silently not actually do anything for sub interpreters.

The only place this would probably cause a problem would be for mod_wsgi where it 
was itself calling sys.exitfunc() on sub interpreters to ensure they were run. Since 
mod_wsgi has to change for Python 3.0 anyway, to call atexit._run_exitfuncs, with a 
bit more work mod_wsgi can just replace atexit module altogether in sub interpreter 
context and have mod_wsgi track the callback functions and trigger them.

By having atexit module ignore stuff for sub interpreters, at least for now avoid 
problem of callbacks against sub interpreters being execute by Py_Finalize() in main 
interpreter context.

And no I haven't looked at how PEP 3121 has changed things in Python 3.0. Up till 
now I hadn't seen any problems to suggest I may need to look at it.

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


More information about the Python-bugs-list mailing list