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.
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 ().