blob: 2fe5543326372ab6096266dd9441bbed44380ebf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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)
|