Finalize

class nvidia_resiliency_ext.inprocess.finalize.Finalize[source]

Abstract base class for finalize argument for inprocess.Wrapper.

Finalize brings the process into a state where a restart of the wrapped function may be attempted, e.g.: deinitialize any global variables or synchronize with any asynchronous tasks issued by the wrapped function that was not already performed by exception handlers in the wrapped function.

Any failure during execution of Finalize should raise an exception. In this case the health check is skipped, exception is reraised by the wrapper, and it should cause termination of the main Python interpreter process.

Finalize class is executed after a fault was detected, distributed group was destroyed, but before the inprocess.health_check.HealthCheck is performed.

Multiple instances of Finalize could be composed with inprocess.Compose to achieve the desired behavior.

class nvidia_resiliency_ext.inprocess.finalize.ThreadedFinalize(timeout, fn, args=(), kwargs=None)[source]

Executes the provided finalize fn function with specified positional and keyword arguments in a separate threading.Thread.

Raises an exception if execution takes longer than the specified timeout.

Parameters:
  • timeout (timedelta) – timeout for a thread executing fn

  • fn (Callable[[...], Any]) – function to be executed

  • args (tuple[Any, ...] | None) – tuple of positional arguments

  • kwargs (dict[str, Any] | None) – dictionary of keyword arguments