Signal Handling

The darc.signal module contains the handlers for OS-level signals, c.f. signal, for the darc module.

darc.signal.exit_signal(signum=None, frame=None)[source]

Handler for exiting signals.

If the current process is not the main process, the function shall transfer the signal to the main process.

Parameters:
  • signum (Union[int, Signals, None]) – The signal to handle.

  • frame (types.FrameType) – The traceback frame from the signal.

Return type:

None

darc.signal.generic_handler(signum=None, frame=None)[source]

Generic signal handler.

If the current process is not the main process, the function shall transfer the signal to the main process.

The function is to be registered through signal.signal() and calls all registered signal handlers from the _HANDLER_REGISTRY mapping.

Parameters:
  • signum (Union[int, Signals, None]) – The signal to handle.

  • frame (types.FrameType) – The traceback frame from the signal.

Return type:

None

darc.signal.register(signum, handler, *, _index=None)[source]

Register signal handler.

Parameters:
Keyword Arguments:

_index – Position index for the signal handler function.

Return type:

Union[Callable[[Signals, FrameType], Any], int, Handlers, None]

See also

The signal handler functions will be saved into _HANDLER_REGISTRY.

darc.signal._HANDLER_REGISTRY: Dict[int, List[Callable[[int | Signals | None, frame | None], Any]]] = {}

Dict[int, List[Callable[[Optional[Union[int, Signals]], Optional[FrameType]], Any]]]: List of registered custom signal handlers.