Chapter XIV: application building blocks -atexit: program closes callback - callback revoked

14.10.3 revoke callback
to revoke an exit callback, you can use the unregister () to remove it from the registry.

import atexit

def my_cleanup(name):
    print('my_cleanup({})'.format(name))

atexit.register(my_cleanup,'first')
atexit.register(my_cleanup,'second')
atexit.register(my_cleanup,'third')

atexit.unregister(my_cleanup)

All calls to the same callback is revoked, regardless of how many times it is registered.
Here Insert Picture Description
Delete the original unregistered callback will not be considered a mistake.

import atexit

def my_cleanup(name):
    print('my_cleanup({})'.format(name))

if False:
    atexit.register(my_cleanup,'never registered')

atexit.unregister(my_cleanup)

Because it will quietly ignore unknown callback, so even in the registered sequence is unknown can be used unregister ().
Here Insert Picture Description

Guess you like

Origin blog.csdn.net/weixin_43193719/article/details/94639663