homepage

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.

classification
Title: document behavior of calling atexit.register() while atexit._run_exitfuncs is running
Type: Stage:
Components: Documentation Versions:
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, martin.panter, skip.montanaro
Priority: low Keywords:

Created on 2014年11月13日 20:52 by skip.montanaro, last changed 2022年04月11日 14:58 by admin.

Messages (2)
msg231135 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2014年11月13日 20:52
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.
msg231354 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2014年11月19日 05:08
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
History
Date User Action Args
2022年04月11日 14:58:10adminsetgithub: 67056
2015年07月21日 07:43:20ethan.furmansetnosy: - ethan.furman
2014年11月19日 05:08:20ethan.furmansetmessages: + msg231354
2014年11月14日 22:18:07martin.pantersetnosy: + martin.panter
2014年11月13日 20:57:55ethan.furmansetnosy: + ethan.furman
2014年11月13日 20:52:37skip.montanarocreate

AltStyle によって変換されたページ (->オリジナル) /