atexit.register does not return the registered function. IMHO, it should.
Carsten Haese
carsten at uniqsys.com
Thu Nov 16 11:38:21 EST 2006
On Thu, 2006-11-16 at 08:03 -0800, prouleau001 at gmail.com wrote:
> @atexit.register
> def goodbye():
> print "Goodbye, terminating..."
>
>
> However, there is one fundamental problem with this: atexit.register()
> returns None. Since the above code corresponds to::
>
>
> def goodbye():
> print "Goodbye, terminating..."
> goodbye = atexit.register(goodbye)
>
> the code registers goodbye but right after it binds goodbye to None!
While it wouldn't hurt to have atexit.register return the function it
registered, this "problem" is only a problem if you wish to call the
function manually, since atexit already registered the reference to the
intended function before your reference to it gets rebound to None.
Normally one would register a function with atexit precisely because
they don't want to call it manually.
-Carsten
More information about the Python-list
mailing list