"""Create fallback_executor
Generated by Phi-Octopus Eden
2025-11-08 20:04:01.624958
"""

```python
from typing import Callable, Any, Union


class FallbackExecutor:
    """
    A class that provides a fallback mechanism for executing functions.
    If the primary function execution fails, it attempts to run an alternative function.

    Args:
        primary_func: The main function to be executed. Should accept keyword arguments (kwargs).
        fallback_func: An optional secondary function as a backup if the primary function fails.
                       It should have the same signature as `primary_func`.
    """

    def __init__(self, primary_func: Callable[..., Any], fallback_func: Callable[..., Any] = None):
        self.primary_func = primary_func
        self.fallback_func = fallback_func

    def execute(self, **kwargs) -> Union[Any, str]:
        """
        Execute the primary function with given keyword arguments.
        If an exception occurs, attempt to run the fallback function.

        Args:
            kwargs: Keyword arguments to be passed to both functions.

        Returns:
            The result of the executed function or a message indicating failure if both fail.
        """
        try:
            return self.primary_func(**kwargs)
        except Exception as e:
            if self.fallback_func:
                try:
                    return self.fallback_func(**kwargs)
                except Exception as fe:
                    return f"Both primary and fallback functions failed: {e}, {fe}"
            else:
                return str(e)


# Example usage
def divide(a: float, b: float) -> float:
    """
    Divide two numbers.
    """
    return a / b


def safe_divide(a: float, b: float) -> float:
    """
    Safe division with handling for zero division error.
    """
    if b == 0:
        return 0.0
    return a / b


fallback_executor = FallbackExecutor(primary_func=divide, fallback_func=safe_divide)

# Test successful execution
result = fallback_executor.execute(a=10, b=2)
print(result)  # Output: 5.0

# Test failure and fallback
result = fallback_executor.execute(a=10, b=0)
print(result)  # Output: 0.0 (from safe_divide)

# Test primary function failure only
fallback_executor = FallbackExecutor(primary_func=lambda a, b: 1 / 0, fallback_func=safe_divide)
result = fallback_executor.execute(a=10, b=0)
print(result)  # Output: 0.0 (from safe_divide)
```