The circuit breaker pattern prevents cascading failures by "tripping" after
consecutive errors and blocking calls while the downstream service recovers.
Implement create_circuit_breaker(threshold, cooldown):
threshold — consecutive failures needed to open the circuit.cooldown — number of blocked calls before a test call is allowed.States:
cooldown blocked calls → HALF_OPEN. - Success → CLOSED (reset failure counter).
- Failure → OPEN (reset cooldown counter).
cb['call'](fn) — fn is () -> result (raises on failure).
Returns the fn result, or raises a CircuitOpenError when blocked.
Sample tests