5. Utilities module
The util module provides some functions used by most fand modules.
It provides a terminate() function to make the daemon and its threads
terminate cleanly.
It provide a when_terminate() function decorator to add
functions to call when terminate() is called, allowing custom cleanup
from modules.
It also has a default signal handler, and a default argument parser.
5.1. Python API
5.1.1. terminate
-
fand.util.terminate(error: Optional[str] = None) → None[source]
Function terminating the program
Sets the terminate flag (see terminating()), and does some cleanup
(see when_terminate())
| Parameters: | error – Error message to print |
5.1.2. sys_exit
-
fand.util.sys_exit() → NoReturn[source]
Exit the program with the error from terminate() if any
5.1.3. terminating
-
fand.util.terminating() → bool[source]
Returns True if the program is terminating, else False
5.1.4. when_terminate
-
fand.util.when_terminate(function: Callable, *args, **kwargs) → None[source]
Add function to call when terminating
| Parameters: |
- function – Function to call
- args – Arguments to call the function with
- kwargs – Keyworded arguments to call the function with
|
5.1.5. sleep
-
fand.util.sleep(secs: float) → None[source]
Sleep some time, stops if terminating
| Parameters: | secs – Number of seconds to sleep |
5.1.6. default_signal_handler
-
fand.util.default_signal_handler(sig: int, _: Any) → None[source]
Default signal handler
5.1.7. parse_args
-
fand.util.parse_args(parser: argparse.ArgumentParser) → argparse.Namespace[source]
Add common arguments, parse arguments, set root logger verbosity
| Parameters: | parser – Argument parser to use |