bpo-17852: Revert incorrect fix based on misunderstanding of _Py_PyAtExit() semantics by pitrou · Pull Request #4826 · python/cpython
I understand that if the _io module wins, the atexit callbacks are never called. It should be possible to write a test to ensure that atexit callbacks are called, no?
test_atexit only has unit tests calling directly atexit._run_exitfuncs() and so not really testing the atexit feature. Maybe we need at least one unit test in test_atexit checks the a print("at exit") is executed... at exit, using a subprocess?
Here I understand that atexit always wins, and so Neil's fix never works. Yet another reason for write a test checking that all files are flushed at exit :-) I know how hard it is to make such tests reliable, since Python shutdown process is a mess :-(