[issue15233] atexit: guarantee order of execution of registered functions?
New submission from Georg Brandl <georg@python.org>: Currently, the atexit docs state "The order in which the functions are called is not defined" in the introduction and "all functions registered are called in last in, first out order" in the docs of the atexit() function. While the latter is correct, I don't think we should guarantee that behaviour by documenting it. Suggestions? ---------- assignee: docs@python components: Documentation messages: 164454 nosy: docs@python, georg.brandl, loewis, pitrou priority: normal severity: normal status: open title: atexit: guarantee order of execution of registered functions? versions: Python 2.7, Python 3.2, Python 3.3 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15233> _______________________________________
Raymond Hettinger <raymond.hettinger@gmail.com> added the comment: I believe it should be guaranteed behavior and that code may reasonably want to have a predictable sequence of unwinding behaviors. ---------- nosy: +rhettinger _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15233> _______________________________________
Antoine Pitrou <pitrou@free.fr> added the comment:
I believe it should be guaranteed behavior and that code may reasonably want to have a predictable sequence of unwinding behaviors.
Agreed. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15233> _______________________________________
Charles-François Natali <neologix@free.fr> added the comment: It is guaranteed by libc's atexit(3), and should also be guaranteed here. ---------- nosy: +neologix _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15233> _______________________________________
Larry Hastings <larry@hastings.org> added the comment: +1 to guaranteeing the order. ---------- nosy: +larry _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15233> _______________________________________
Larry Hastings <larry@hastings.org> added the comment: Here's a patch. I read the implementation to find out what it does, then documented it. Happily it does the sane thing. ---------- keywords: +patch Added file: http://bugs.python.org/file26230/larry.atexit.1.diff _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15233> _______________________________________
Antoine Pitrou <pitrou@free.fr> added the comment:
Here's a patch. I read the implementation to find out what it does, then documented it. Happily it does the sane thing.
Is it tested for? ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15233> _______________________________________
Éric Araujo <merwok@netwok.org> added the comment: See #9788 for previous discussion. ---------- nosy: +eric.araujo _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15233> _______________________________________
Raymond Hettinger <raymond.hettinger@gmail.com> added the comment: The patch wording is fine. However, I would avoid the "note" markup. It is visually distracting and there isn't a reason to pull this out of the main text. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15233> _______________________________________
Larry Hastings <larry@hastings.org> added the comment:
Is it tested for?
Amusingly enough, yes. test_order() in Lib/test/test_atexit.py already ensures reverse order. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15233> _______________________________________
Larry Hastings <larry@hastings.org> added the comment:
I would avoid the "note" markup. It is visually distracting and there isn't a reason to pull this out of the main text.
I think it's an improvement; it helps draw the eye to an important warning. Does anyone else have an opinion one way or another? ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15233> _______________________________________
Antoine Pitrou <pitrou@free.fr> added the comment:
Does anyone else have an opinion one way or another?
I'm neutral. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15233> _______________________________________
Terry J. Reedy <tjreedy@udel.edu> added the comment: I agree with Raymond. You might, however, emphasize 'normal' in 'normal interpreter termination'. That is the key point. The 'note' merely explains 'abnormal'. ---------- nosy: +terry.reedy _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15233> _______________________________________
Changes by Éric Araujo <merwok@netwok.org>: ---------- nosy: +benjamin.peterson, giampaolo.rodola, meador.inge, python-dev _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15233> _______________________________________
Larry Hastings <larry@hastings.org> added the comment: Okay, I'll remove the ".. note". Checking in shortly. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15233> _______________________________________
Roundup Robot <devnull@psf.upfronthosting.co.za> added the comment: New changeset f8b520b6f654 by Larry Hastings in branch 'default': - Issue #15233: Python now guarantees that callables registered with http://hg.python.org/cpython/rev/f8b520b6f654 ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15233> _______________________________________
Larry Hastings <larry@hastings.org> added the comment: So, it's checked in to trunk. Shall I also backport to 2.7 and 3.2 as the issue suggests? ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15233> _______________________________________
Antoine Pitrou <pitrou@free.fr> added the comment:
Shall I also backport to 2.7 and 3.2 as the issue suggests?
If the tests are there, yes! ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15233> _______________________________________
Larry Hastings <larry@hastings.org> added the comment: I have been meditating on this, and I'm not sure we should change 2.7. 3.2 might be okay. The thing is, I fear we're not just talking about CPython implementation details, we're talking about the Python Standard Library. The existing documentation clearly gives alternative implementations free license to call atexit registered functions in any order they like. So it's conceivable that other implementations don't guarantee reverse order. I don't know what the right thing is to do here. It seems like we could define atexit's behavior for 2.7 *if* all the major alternative implementations happily also implicitly guarantee reverse order. Failing that we probably shouldn't touch it. Or we could just document that reverse order is guaranteed in CPython only. Of course, there are no alternative implementations that support 3.2. That's why I think 3.2 might be okay. It does seem strange to redefine part of the implicit language spec more than a year after the release shipped though. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15233> _______________________________________
Raymond Hettinger <raymond.hettinger@gmail.com> added the comment: +1 for backport. There's no benefit to leaving ambiguity floating about, nor was there ever any intention for the behavior to have been different. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15233> _______________________________________
Charles-François Natali added the comment: Ping. Like Raymond, I think there's no reason to leave ambiguity in 2.7 and 3.2, so this doc patch is probably worth backporting. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15233> _______________________________________
Charles-François Natali added the comment: Unless anyone objects, I'll backport it soonish. ---------- stage: -> commit review _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15233> _______________________________________
Roundup Robot added the comment: New changeset 84d74eb7a341 by Charles-François Natali in branch '2.7': Issue #15233: Python now guarantees that callables registered with the atexit http://hg.python.org/cpython/rev/84d74eb7a341 ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15233> _______________________________________
Charles-François Natali added the comment: Backported to 2.7. ---------- resolution: -> fixed stage: commit review -> committed/rejected status: open -> closed versions: -Python 3.2 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15233> _______________________________________
participants (8)
-
Antoine Pitrou
-
Charles-François Natali
-
Georg Brandl
-
Larry Hastings
-
Raymond Hettinger
-
Roundup Robot
-
Terry J. Reedy
-
Éric Araujo