Uh oh!
There was an error while loading. Please reload this page.
bpo-17852: Revert incorrect fix based on misunderstanding of _Py_PyAtExit() semantics - #4826
Conversation
pitrou
commented
Dec 12, 2017
vstinner
commented
Dec 12, 2017
pitrou
commented
Dec 12, 2017
Please read the PR description :-) |
vstinner
commented
Dec 12, 2017
The PR description isn't very helpful. I undertand that Neil implements the change "Maintain a list of BufferedWriter objects. Flush them on exit." but that it doesn't work sometimes. Would you mind to explain when it doesn't work? Sadly, it seems like the commit 0a1ff24 didn't add a new test, so it's easily see how to trigger a potential bug. |
pitrou
commented
Dec 13, 2017
It's simple: both (if you don't understand, I really suggest you study the code) |
vstinner
commented
Dec 13, 2017
Would it be possible to write a test for that, to prevent regression? |
pitrou
commented
Dec 13, 2017
We could add an assertion rather than a test... |
vstinner
commented
Dec 13, 2017
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 :-( |
pitrou
commented
Dec 13, 2017
Should I add it as part of this PR? |
vstinner
commented
Dec 13, 2017
Technically, I would prefer to see it in a different commit, instead of hidden in a "revert" commit. So another PR would be better, and it would allow to backport the new test. |
pitrou
commented
Dec 13, 2017
Ok, so I would like to merge this PR soon. |
vstinner
left a comment
There was a problem hiding this comment.
LGTM.
Ok, I understood the bug.
I don't think that this revert means that it's not possible to flush files at exit. Just that the fix was wrong, and that we need more time to design the fix properly.
vstinner
commented
Dec 13, 2017
pitrou
commented
Dec 13, 2017
I expect the correct fix will to call the |
nascheme
commented
Dec 13, 2017
I think I have a proper fix, uses the atexit module. Will create a PR shortly. |
The fix committed in #3372 uses
_Py_PyAtExit. Unfortunately this function does not add a new callback, it merely replaces the current one. In other words,_Py_PyAtExitis only meant to be called by theatexitmodule and nothing else.https://bugs.python.org/issue17852