PyBreaker includes optional support for Tornado coroutines, allowing you to protect async integration points with the same circuit breaker semantics as synchronous code. When Tornado is installed,Documentation Index
Fetch the complete documentation index at: https://mintlify.com/danielfm/pybreaker/llms.txt
Use this file to discover all available pages before exploring further.
CircuitBreaker gains the ability to wrap @gen.coroutine functions and propagate circuit state correctly through the coroutine lifecycle.
Installation
Decorator with Async Support
To protect a Tornado coroutine with the decorator pattern, pass__pybreaker_call_async=True as a keyword argument when applying the breaker. This signals CircuitBreaker.__call__ to route the call through call_async() instead of the synchronous call() path.
__pybreaker_call_async=True flag is consumed by CircuitBreaker.__call__ and is not forwarded to the wrapped function. The decorator order matters: @db_breaker(...) must be applied above @gen.coroutine so that the circuit breaker wraps the coroutine factory, not the raw function.
Direct Async Call
For cases where you cannot or do not want to use the decorator, callcb.call_async() directly. Pass the coroutine function as the first argument, followed by any positional and keyword arguments to forward to it.
CircuitBreaker.call_async(func, *args, **kwargs)
call_async returns a Tornado Future. yield it inside another @gen.coroutine or use it with IOLoop.run_sync to get the result.
Error Handling
Error handling behaviour is identical to the synchronous case. When the circuit is open,call_async raises CircuitBreakerError immediately without attempting the call. When the circuit is closed or half-open, a failure inside the coroutine is counted against the failure threshold as usual.
Tornado support is optional. If Tornado is not installed, calling
call_async() or decorating with __pybreaker_call_async=True will raise ImportError: No module named tornado. PyBreaker checks for Tornado at import time and exposes the HAS_TORNADO_SUPPORT boolean if you need to detect availability at runtime.