Usage#
- exception evacuator.NeedEvacuation#
- evacuator.evacuator(func: ~evacuator.core.T | None = None, exception: ~typing.Type[Exception] | tuple[~typing.Type[Exception], ...] = <class 'evacuator.exception.NeedEvacuation'>, exit_code: int = 125) T | Callable[[T], T] #
Catch specific exception and exit with exit code.
Can be used as either decorator or context manager
- Parameters:
- funcCallable
Function which should we wrapped with a decorator
- exceptionException | tuple[Exception, …], default
evacuator.exception.NeedEvacuation
Exception or exceptions which should be caught
- exit_codeint, default
125
(UnixECANCELED
) Code which process should be exited with
Examples
Decorator example
from evacuator import evacuator @evacuator def main(): raise NeedEvacuation("abc") @evacuator(exception=(MyException, RuntimeError)) def main(): raise MyException("abc") @evacuator(exception=MyException, exit_code=5) def main(): raise MyException("abc")
Context manager example
from evacuator import evacuator with evacuator(): raise NeedEvacuation("abc") with evacuator(exception=(MyException, RuntimeError)): raise MyException("abc") with evacuator(exception=MyException, exit_code=5): raise MyException("abc")