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 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:10 | admin | set | github: 67056 |
| 2015年07月21日 07:43:20 | ethan.furman | set | nosy:
- ethan.furman |
| 2014年11月19日 05:08:20 | ethan.furman | set | messages: + msg231354 |
| 2014年11月14日 22:18:07 | martin.panter | set | nosy:
+ martin.panter |
| 2014年11月13日 20:57:55 | ethan.furman | set | nosy:
+ ethan.furman |
| 2014年11月13日 20:52:37 | skip.montanaro | create | |