Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-17852: Revert incorrect fix based on misunderstanding of _Py_PyAtExit() semantics #4826

Merged
merged 1 commit into from
Dec 13, 2017

Conversation

pitrou
Copy link
Member

@pitrou pitrou commented Dec 12, 2017

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_PyAtExit is only meant to be called by the atexit module and nothing else.

https://bugs.python.org/issue17852

@pitrou
Copy link
Member Author

pitrou commented Dec 12, 2017

@nascheme

@vstinner
Copy link
Member

bpo-17852: Revert incorrect fix based on misunderstanding of _Py_PyAtExit() semantics #4826

Would you mind to explain what is wrong? What is the incorrect fix? Are you talking about the commit 0a1ff24 made by @nascheme?

@pitrou
Copy link
Member Author

pitrou commented Dec 12, 2017

Would you mind to explain what is wrong?

Please read the PR description :-)

@vstinner
Copy link
Member

Please read the PR description :-)

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
Copy link
Member Author

pitrou commented Dec 13, 2017

Would you mind to explain when it doesn't work?

It's simple: both _io and atexit call _Py_PyAtExit when initialized, but that function overwrites a single callback. So both modules end up fighting for having their callback executed at shutdown :-)

(if you don't understand, I really suggest you study the code)

@vstinner
Copy link
Member

It's simple: both _io and atexit call _Py_PyAtExit when initialized, but that function overwrites a single callback. So both modules end up fighting for having their callback executed at shutdown :-)

Would it be possible to write a test for that, to prevent regression?

@pitrou
Copy link
Member Author

pitrou commented Dec 13, 2017

Would it be possible to write a test for that, to prevent regression?

We could add an assertion rather than a test...

@vstinner
Copy link
Member

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
Copy link
Member Author

pitrou commented Dec 13, 2017

Maybe we need at least one unit test in test_atexit checks the a print("at exit") is executed... at exit, using a subprocess?

Should I add it as part of this PR?

@vstinner
Copy link
Member

Should I add it as part of this PR?

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
Copy link
Member Author

pitrou commented Dec 13, 2017

Ok, so I would like to merge this PR soon.

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member

@pitrou wrote the PR #4828: non-regression test for test_atexit.

@pitrou
Copy link
Member Author

pitrou commented Dec 13, 2017

I expect the correct fix will to call the atexit.register function.

@vstinner vstinner merged commit 317def9 into python:master Dec 13, 2017
@pitrou pitrou deleted the revert_incorrect_io_atexit branch December 13, 2017 00:39
@nascheme
Copy link
Member

I think I have a proper fix, uses the atexit module. Will create a PR shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants