Issue 15233: atexit: guarantee order of execution of registered functions? (original) (raw)

process

Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: benjamin.peterson, docs@python, eric.araujo, georg.brandl, giampaolo.rodola, larry, loewis, meador.inge, neologix, pitrou, python-dev, rhettinger, terry.reedy
Priority: normal Keywords: patch

Created on 2012-07-01 07:58 by georg.brandl, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
larry.atexit.1.diff larry,2012-07-02 14:24 First patch, just doc changes. review
Messages (23)
msg164454 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2012-07-01 07:58
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?
msg164458 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2012-07-01 08:20
I believe it should be guaranteed behavior and that code may reasonably want to have a predictable sequence of unwinding behaviors.
msg164471 - (view) Author: Charles-François Natali (neologix) * (Python committer) Date: 2012-07-01 10:17
It is guaranteed by libc's atexit(3), and should also be guaranteed here.
msg164472 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2012-07-01 10:20
+1 to guaranteeing the order.
msg164475 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-07-01 11:27
> I believe it should be guaranteed behavior and that code may > reasonably want to have a predictable sequence of unwinding behaviors. Agreed.
msg164516 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2012-07-02 14:24
Here's a patch. I read the implementation to find out what it does, then documented it. Happily it does the sane thing.
msg164517 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-07-02 14:30
> 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?
msg164527 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2012-07-02 19:10
See #9788 for previous discussion.
msg164555 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2012-07-02 21:34
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.
msg164579 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2012-07-03 06:26
> Is it tested for? Amusingly enough, yes. test_order() in Lib/test/test_atexit.py already ensures reverse order.
msg164581 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2012-07-03 06:51
> 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?
msg164588 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-07-03 09:23
> Does anyone else have an opinion one way or another? I'm neutral.
msg164753 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2012-07-06 20:11
I agree with Raymond. You might, however, emphasize 'normal' in 'normal interpreter termination'. That is the key point. The 'note' merely explains 'abnormal'.
msg165482 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2012-07-15 01:16
Okay, I'll remove the ".. note". Checking in shortly.
msg165483 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-07-15 01:21
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
msg165484 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2012-07-15 01:22
So, it's checked in to trunk. Shall I also backport to 2.7 and 3.2 as the issue suggests?
msg165535 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-07-15 16:55
> Shall I also backport to 2.7 and 3.2 as the issue suggests? If the tests are there, yes!
msg165567 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2012-07-16 04:56
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.
msg165576 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2012-07-16 07:01
+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.
msg172599 - (view) Author: Charles-François Natali (neologix) * (Python committer) Date: 2012-10-10 19:31
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.
msg194258 - (view) Author: Charles-François Natali (neologix) * (Python committer) Date: 2013-08-03 13:31
Unless anyone objects, I'll backport it soonish.
msg195803 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-08-21 16:27
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
msg195805 - (view) Author: Charles-François Natali (neologix) * (Python committer) Date: 2013-08-21 16:47
Backported to 2.7.
History
Date User Action Args
2022-04-11 14:57:32 admin set github: 59438
2013-08-21 16:47:44 neologix set status: open -> closedversions: - Python 3.2messages: + resolution: fixedstage: commit review -> resolved
2013-08-21 16:27:53 python-dev set messages: +
2013-08-03 13:31:31 neologix set messages: + stage: commit review
2012-10-10 19:31:11 neologix set messages: +
2012-07-16 07:01:15 rhettinger set messages: +
2012-07-16 04:56:26 larry set messages: +
2012-07-15 16:55:57 pitrou set messages: +
2012-07-15 01:22:22 larry set messages: +
2012-07-15 01:21:15 python-dev set messages: +
2012-07-15 01:16:12 larry set messages: +
2012-07-08 04:38:23 eric.araujo set nosy: + giampaolo.rodola, benjamin.peterson, meador.inge, python-dev
2012-07-06 20:11:59 terry.reedy set nosy: + terry.reedymessages: +
2012-07-03 09:23:24 pitrou set messages: +
2012-07-03 06:51:05 larry set messages: +
2012-07-03 06:26:19 larry set messages: +
2012-07-02 21:34:36 rhettinger set messages: +
2012-07-02 19:10:52 eric.araujo set nosy: + eric.araujomessages: +
2012-07-02 14:30:21 pitrou set messages: +
2012-07-02 14:24:41 larry set files: + larry.atexit.1.diffkeywords: + patchmessages: +
2012-07-01 11:27:14 pitrou set messages: +
2012-07-01 10:20:24 larry set nosy: + larrymessages: +
2012-07-01 10:17:29 neologix set nosy: + neologixmessages: +
2012-07-01 08:20:48 rhettinger set nosy: + rhettingermessages: +
2012-07-01 07:58:41 georg.brandl create