Python Glossary Русский

Python 3.0+atexitfunction

atexit.unregister()

exit handlers

Removes a function from the list of exit handlers — every registration of it at once, whatever the arguments.

Syntax

atexit.unregister(func)

The function is compared with ==, so a lambda passed to register() cannot be removed unless you kept it in a variable. If the function was never registered, nothing happens and nothing is raised — a typo here goes unnoticed. Do not call register() or unregister() from inside a running handler: the behaviour is undefined.

Examples

import atexit
def cleanup(name):
    print('cleanup', name)
atexit.register(cleanup, 'a')
atexit.register(cleanup, 'b')
atexit.register(print, 'остался только этот')
atexit.unregister(cleanup)  # сняты обе регистрации
atexit.unregister(len)  # не регистрировалась — ошибки нет
print('конец')  # → конец / остался только этот

See also

Open in the full glossarydocs.python.orgReport an inaccuracy