GeezerVison is showing github.com — document behavior of calling atexit.register() while atexit._run_exitfuncs is running · Issue #67056 · python/cpython
document behavior of calling atexit.register() while atexit._run_exitfuncs is running #67056Description
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee = None
closed_at = None
created_at = <Date 2014-11-13.20:52:37.164>
labels = ['docs']
title = 'document behavior of calling atexit.register() while atexit._run_exitfuncs is running'
updated_at = <Date 2015-07-21.07:43:20.900>
user = 'https://github.com/smontanaro'
bugs.python.org fields:
activity = <Date 2015-07-21.07:43:20.900>
actor = 'ethan.furman'
assignee = 'docs@python'
closed = False
closed_date = None
closer = None
components = ['Documentation']
creation = <Date 2014-11-13.20:52:37.164>
creator = 'skip.montanaro'
dependencies = []
files = []
hgrepos = []
issue_num = 22867
keywords = []
message_count = 2.0
messages = ['231135', '231354']
nosy_count = 3.0
nosy_names = ['skip.montanaro', 'docs@python', 'martin.panter']
pr_nums = []
priority = 'low'
resolution = None
stage = None
status = 'open'
superseder = None
type = None
url = 'https://bugs.python.org/issue22867'
versions = []
Linked PRs
Activitysmontanaro commented on Nov 13, 2014 ContributorAuthor More actions A discussion on comp.lang.python about prettying up the "if __name__ == 'main__'" idiom led to a suggestion that a decorator could simple register the main function using atexit.register. That looks like it will work, but leaves open the possibility that while main() is running via atexit._run_exitfuncs, other exit functions might be registered.
As currently defined (at least in the Python version with 2.7), I think everything will work fine. Still, the behavior of adding new exit functions during exit is not defined. Would be kind of nice if this behavior was blessed, and then mentioned in the documentation. ethanfurman commented on Nov 19, 2014 From a post by Ian Kelly (https://mail.python.org/pipermail/python-list/2014-November/681073.html)
--------------------------------------------------------------
In fact it seems the behavior does differ between Python 2.7 and Python 3.4:
$ cat testatexit.py
import atexit
@atexit.register
def main():
atexit.register(goodbye)
@atexit.register
def goodbye():
print("Goodbye")
$ python2 testatexit.py
Goodbye
Goodbye
$ python3 testatexit.py
Goodbyeiritkatriel commented on May 13, 2023 The atexit functions are invoked in LIFO order, so I think it's not a good idea to add more after the first one started running. We don't currently forbid, it and I wouldn't argue in favour of doing so, but we shouldn't encourage it. smontanaro commented on May 13, 2023 ContributorAuthor More actions This has been idle for "awhile." Should we just put our heads together and decide how best to document this behavior? iritkatriel commented on May 13, 2023 I'm not sure what the behaviour is. Or rather, what behaviour we want to commit to. smontanaro commented on May 14, 2023 ContributorAuthor More actions I'm not sure that committing to any particular behavior is the right thing to do without some more discussion. Maybe just warn that calling atexit.register after _PyAtExit_Call has been invoked is undefined. There's no mention of that corner case in the 3.11 or 3.12 documentation as it stands. added a commit that references this issue on May 15, 2023gh-67056: document that registering/unregistering an atexit func from…
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|