tracetools_trace.tools.signals module

Signal handling utilities.

exception tracetools_trace.tools.signals.SignalHandledException

Bases: RuntimeError

Exception raised after a signal is handled.

class tracetools_trace.tools.signals.SignalHandlerUtil(release_callback: Callable[[], None] | None = None, raise_after_signal: bool = False, signals: List[int] = [Signals.SIGINT])

Bases: object

Signal handler as a context manager.

Modified version of: https://stackoverflow.com/a/35798485/6476709

tracetools_trace.tools.signals.execute_and_handle_sigint(run_function: Callable[[], None], fini_function: Callable[[], None] | None = None) None

Execute a task and handle SIGINT to always finalize cleanly.

The main task function is interrupted on SIGINT. The finalization function (if provided) is always executed, either after the main task function is done or after it is interrupted.

Parameters:
  • run_function – the task function, which may be interrupted

  • fini_function – the optional finalization/cleanup function