This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2010年09月07日 10:27 by giampaolo.rodola, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| doc-atexit-order-undefined.diff | eric.araujo, 2011年06月10日 17:04 | review | ||
| Messages (15) | |||
|---|---|---|---|
| msg115747 - (view) | Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) | Date: 2010年09月07日 10:27 | |
import atexit @atexit.register def goodbye1(): print(1) @atexit.register def goodbye2(): print(2) The code above prints: 2 1 ...that is, the last registered function is executed first. Wouldn't the contrary be better? |
|||
| msg115749 - (view) | Author: Skip Montanaro (skip.montanaro) * (Python triager) | Date: 2010年09月07日 10:59 | |
I'm sure you can craft cases where one order is preferable to another, but I don't think you can make the case in general that first in, first out is preferable to last in, first out, or any other ordering of exit functions. |
|||
| msg115756 - (view) | Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) | Date: 2010年09月07日 13:20 | |
I think it's not a matter of "preferable" but "most expected" and I see FIFO as the most expected behavior in this case. |
|||
| msg115764 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2010年09月07日 14:20 | |
LIFO looks preferable if you want your setup/teardown code to be properly nested (that is, if I set up A before B, I want B to be torn down before A). |
|||
| msg115769 - (view) | Author: Éric Araujo (eric.araujo) * (Python committer) | Date: 2010年09月07日 14:59 | |
It seems to me that atexit is simple by design: It registers callables that do one thing, period. If you have dependencies in your cleanup code, you should write a function doing the Right ThingTM and register that. This keeps the implementation simple, otherwise we’d have to debate LIFO vs. FIFO, adding an argument to register vs. exposing the list of callables, etc. If you agree, I could make a patch to make the docs more explicit about atexit’s simplicity and lack of guarantee about run order. |
|||
| msg115790 - (view) | Author: Benjamin Peterson (benjamin.peterson) * (Python committer) | Date: 2010年09月07日 18:07 | |
I don't think the order should be defined. |
|||
| msg115791 - (view) | Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) | Date: 2010年09月07日 18:37 | |
Ok, I'll shut up then. =) > If you agree, I could make a patch to make the docs more explicit about > atexit’s simplicity and lack of guarantee about run order. Sure, go ahead. |
|||
| msg116225 - (view) | Author: Meador Inge (meador.inge) * (Python committer) | Date: 2010年09月12日 18:49 | |
I agree with Antoine's LIFO comment. Also, FWIW, the C standard library behaves in a LIFO manner as well (C99 spec - 7.20.4.3 clause 3): "First, all functions registered by the atexit function are called, in the reverse order of their registration,253) except that a function is called after any previously registered functions that had already been called at the time it was registered. If, during the call to any such function, a call to the longjmp function is made that would terminate the call to the registered function, the behavior is undefined." |
|||
| msg138113 - (view) | Author: Éric Araujo (eric.araujo) * (Python committer) | Date: 2011年06月10日 17:04 | |
Here’s a patch. |
|||
| msg138123 - (view) | Author: Charles-François Natali (neologix) * (Python committer) | Date: 2011年06月10日 17:49 | |
> I don't think the order should be defined. I disagree. The C standard explicitely states that the functions are called in LIFO order (which is the natural order in this case). The current implementation guarantees LIFO order, I think it should be documented. |
|||
| msg141393 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2011年07月29日 16:11 | |
New changeset e37fa30c4be4 by Éric Araujo in branch '3.2': Document that atexit execution order is undefined (#9788) http://hg.python.org/cpython/rev/e37fa30c4be4 |
|||
| msg141396 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2011年07月29日 16:13 | |
New changeset df415bfbb652 by Éric Araujo in branch '2.7': Document that atexit execution order is undefined (#9788) http://hg.python.org/cpython/rev/df415bfbb652 |
|||
| msg141397 - (view) | Author: Éric Araujo (eric.araujo) * (Python committer) | Date: 2011年07月29日 16:19 | |
Given Benjamin and Giampaolo’s support, I committed my patch, so that at least the current behavior is documented. I personally have no opinion on LIFO vs. FIFO vs. undefined; I just think that the atexit module is not a wrapper around C’s atexit, and as such not bound by the same rules, and undefined sounds fine. If you feel very strongly about that, then please follow up on python-dev. |
|||
| msg141409 - (view) | Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) | Date: 2011年07月29日 19:33 | |
Thanks. After all, I think that "keeping atexit simple" is the best solution and a doc adjustement is just fine. |
|||
| msg164964 - (view) | Author: Éric Araujo (eric.araujo) * (Python committer) | Date: 2012年07月08日 04:37 | |
Reopened as #15233. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:06 | admin | set | github: 53997 |
| 2012年07月08日 04:37:52 | eric.araujo | set | messages: + msg164964 |
| 2011年07月29日 19:33:19 | giampaolo.rodola | set | messages: + msg141409 |
| 2011年07月29日 16:19:15 | eric.araujo | set | status: open -> closed resolution: fixed messages: + msg141397 stage: patch review -> resolved |
| 2011年07月29日 16:13:47 | python-dev | set | messages: + msg141396 |
| 2011年07月29日 16:11:12 | python-dev | set | nosy:
+ python-dev messages: + msg141393 |
| 2011年06月10日 17:49:32 | neologix | set | nosy:
+ neologix messages: + msg138123 |
| 2011年06月10日 17:04:31 | eric.araujo | set | files:
+ doc-atexit-order-undefined.diff versions: + Python 3.3, - Python 3.1 messages: + msg138113 keywords: + needs review, patch resolution: accepted -> (no value) stage: needs patch -> patch review |
| 2011年03月19日 19:11:02 | skip.montanaro | set | nosy:
- skip.montanaro |
| 2010年09月12日 18:49:36 | meador.inge | set | nosy:
+ meador.inge messages: + msg116225 |
| 2010年09月08日 00:56:05 | eric.araujo | set | versions:
+ Python 3.1, Python 2.7 nosy: skip.montanaro, pitrou, giampaolo.rodola, benjamin.peterson, eric.araujo assignee: eric.araujo components: + Documentation, - Library (Lib) resolution: accepted stage: needs patch |
| 2010年09月07日 18:37:47 | giampaolo.rodola | set | messages: + msg115791 |
| 2010年09月07日 18:07:09 | benjamin.peterson | set | nosy:
+ benjamin.peterson messages: + msg115790 |
| 2010年09月07日 14:59:10 | eric.araujo | set | messages: + msg115769 |
| 2010年09月07日 14:20:39 | pitrou | set | nosy:
+ pitrou messages: + msg115764 |
| 2010年09月07日 13:20:47 | giampaolo.rodola | set | messages: + msg115756 |
| 2010年09月07日 11:59:43 | eric.araujo | set | nosy:
+ eric.araujo |
| 2010年09月07日 10:59:17 | skip.montanaro | set | nosy:
+ skip.montanaro messages: + msg115749 |
| 2010年09月07日 10:27:12 | giampaolo.rodola | create | |