Code Room
Code reviewHard
Question
Review this Python circuit breaker. When open, after a cooldown it moves to half-open and lets calls through to test recovery.
What a strong answer looks like
Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix — specific and kind.
Learn the concepts
class Breaker: def call(self, fn): if self.state == "open": if time.time() - self.opened_at >= self.cooldown: self.state = "half_open" else: raise BreakerOpen() try: r = fn() self.state = "closed"; self.failures = 0 return r except Exception: self.failures += 1 self.state = "open"; self.opened_at = time.time() raiseRun or narrate your approach, then ask the coach.