bpo-17852: Revert incorrect fix based on misunderstanding of _Py_PyAtExit() semantics#4826
Conversation
Sorry, something went wrong.
Please read the PR description :-) |
Sorry, something went wrong.
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. |
Sorry, something went wrong.
It's simple: both (if you don't understand, I really suggest you study the code) |
Sorry, something went wrong.
Would it be possible to write a test for that, to prevent regression? |
Sorry, something went wrong.
We could add an assertion rather than a test... |
Sorry, something went wrong.
|
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 :-( |
Sorry, something went wrong.
Should I add it as part of this PR? |
Sorry, something went wrong.
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. |
Sorry, something went wrong.
|
Ok, so I would like to merge this PR soon. |
Sorry, something went wrong.
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.
Sorry, something went wrong.
Sorry, something went wrong.
|
I expect the correct fix will to call the |
Sorry, something went wrong.
|
I think I have a proper fix, uses the atexit module. Will create a PR shortly. |
Sorry, something went wrong.
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