Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
f00d0932
Commit
f00d0932
authored
Nov 16, 2006
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bug #1597824: return the registered function from atexit.register()
to facilitate usage as a decorator.
parent
bc9f501e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
0 deletions
+22
-0
Doc/lib/libatexit.tex
Doc/lib/libatexit.tex
+16
-0
Lib/atexit.py
Lib/atexit.py
+3
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Doc/lib/libatexit.tex
View file @
f00d0932
...
...
@@ -44,6 +44,10 @@ If an exception is raised during execution of the exit handlers, a
traceback is printed (unless
\exception
{
SystemExit
}
is raised) and the
exception information is saved. After all exit handlers have had a
chance to run the last exception to be raised is re-raised.
\versionchanged
[This function now returns
\var
{
func
}
which makes it
possible to use it as a decorator without binding the
original name to
\code
{
None
}
]
{
2.6
}
\end{funcdesc}
...
...
@@ -92,3 +96,15 @@ atexit.register(goodbye, 'Donny', 'nice')
# or:
atexit.register(goodbye, adjective='nice', name='Donny')
\end{verbatim}
Usage as a decorator:
\begin{verbatim}
import atexit
@atexit.register
def goodbye():
print "You are now leaving the Python sector."
\end{verbatim}
This obviously only works with functions that don't take arguments.
Lib/atexit.py
View file @
f00d0932
...
...
@@ -40,8 +40,11 @@ def register(func, *targs, **kargs):
func - function to be called at exit
targs - optional arguments to pass to func
kargs - optional keyword arguments to pass to func
func is returned to facilitate usage as a decorator.
"""
_exithandlers
.
append
((
func
,
targs
,
kargs
))
return
func
if
hasattr
(
sys
,
"exitfunc"
):
# Assume it's another registered exit function - append it to our list
...
...
Misc/NEWS
View file @
f00d0932
...
...
@@ -98,6 +98,9 @@ Core and builtins
Library
-------
- Bug #1597824: return the registered function from atexit.register()
to facilitate usage as a decorator.
- Patch #1360200: Use unmangled_version RPM spec field to deal with
file name mangling.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment