capcat.core.timeout_wrapper

File: Application/capcat/core/timeout_wrapper.py

Description

Timeout wrapper utilities for preventing hanging operations. Provides robust timeout handling for network operations that may hang.

Functions

with_timeout

def with_timeout(func: Callable, timeout_seconds: int = 30) -> Callable

Wrapper that adds timeout functionality to any function call.

Args: func: Function to execute with timeout timeout_seconds: Maximum time to wait for function completion

Returns: Function result or None if timeout occurred

Parameters:

  • func (Callable)
  • timeout_seconds (int) optional

Returns: Callable

safe_network_operation

def safe_network_operation(operation: Callable) -> Optional[Any]

Execute a network operation with timeout protection.

Args: operation: Network function to execute *args: Arguments for the operation timeout: Timeout in seconds **kwargs: Keyword arguments for the operation

Returns: Operation result or None if timeout/error occurred

Parameters:

  • operation (Callable)

Returns: Optional[Any]

wrapper

def wrapper() -> Optional[Any]

Returns: Optional[Any]

target

def target()