Skip to content

document behavior of calling atexit.register() while atexit._run_exitfuncs is running #67056

Description

@smontanaro
BPO 22867
Nosy @smontanaro, @vadmium

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

Activity

  1. smontanaro commented on Nov 13, 2014

    @smontanaro
    ContributorAuthor

    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.

  2. ethanfurman commented on Nov 19, 2014

    @ethanfurman
    Member

    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
    Goodbye
  3. transferred this issue fromon Apr 10, 2022
  4. iritkatriel commented on May 13, 2023

    @iritkatriel
    Member

    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.

  5. smontanaro commented on May 13, 2023

    @smontanaro
    ContributorAuthor

    This has been idle for "awhile." Should we just put our heads together and decide how best to document this behavior?

  6. iritkatriel commented on May 13, 2023

    @iritkatriel
    Member

    I'm not sure what the behaviour is. Or rather, what behaviour we want to commit to.

  7. smontanaro commented on May 14, 2023

    @smontanaro
    ContributorAuthor

    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.

  8. added 2 commits that reference this issue on May 14, 2023
  9. added a commit that references this issue on May 15, 2023
  10. added a commit that references this issue on May 15, 2023
  11. added a commit that references this issue on May 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions