diff options
Diffstat (limited to 'python/knot_resolver/utils/custom_atexit.py')
-rw-r--r-- | python/knot_resolver/utils/custom_atexit.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/python/knot_resolver/utils/custom_atexit.py b/python/knot_resolver/utils/custom_atexit.py new file mode 100644 index 00000000..2fe55433 --- /dev/null +++ b/python/knot_resolver/utils/custom_atexit.py @@ -0,0 +1,20 @@ +""" +Custom replacement for standard module `atexit`. We use `atexit` behind the scenes, we just add the option +to invoke the exit functions manually. +""" + +import atexit +from typing import Callable, List + +_at_exit_functions: List[Callable[[], None]] = [] + + +def register(func: Callable[[], None]) -> None: + _at_exit_functions.append(func) + atexit.register(func) + + +def run_callbacks() -> None: + for func in _at_exit_functions: + func() + atexit.unregister(func) |