network
Base class for network utilities, providing exponential backoff time calculation.
- pipecat.utils.network.exponential_backoff_time(attempt: int, min_wait: float = 4, max_wait: float = 10, multiplier: float = 1) float[source]
Calculate exponential backoff wait time.
- Parameters:
attempt – Current attempt number (1-based)
min_wait – Minimum wait time in seconds
max_wait – Maximum wait time in seconds
multiplier – Base multiplier for exponential calculation
- Returns:
Wait time in seconds
- class pipecat.utils.network.QuickFailureResult(is_quick_failure: bool, should_give_up: bool)[source]
Bases:
objectOutcome of recording one failed connection attempt.
- Parameters:
is_quick_failure – Whether this attempt lasted less than the tracker’s
min_stable_duration.should_give_up – Whether
max_consecutive_failuresquick failures have now happened in a row and the caller should stop retrying.
- is_quick_failure: bool
- should_give_up: bool
- class pipecat.utils.network.QuickFailureTracker(min_stable_duration: float = 5.0, max_consecutive_failures: int = 3)[source]
Bases:
objectDetects a connection that keeps failing immediately after connecting.
Exponential backoff alone doesn’t help when a connection attempt succeeds just enough to fail again right away (e.g. a server that accepts a WebSocket handshake but then immediately rejects invalid credentials) — waiting longer between attempts won’t fix that, only stopping will.
Call
record()with how long each failed attempt lasted. Oncemax_consecutive_failuresattempts in a row each lasted undermin_stable_durationseconds, the result’sshould_give_upis True, telling the caller to stop retrying instead of trying again.- __init__(min_stable_duration: float = 5.0, max_consecutive_failures: int = 3)[source]
Initialize the tracker.
- Parameters:
min_stable_duration – Minimum time, in seconds, a connection must survive to be considered stable rather than a quick failure.
max_consecutive_failures – Number of consecutive quick failures after which
record()reports that the caller should give up.
- record(duration: float) QuickFailureResult[source]
Record a failed connection attempt that lasted
durationseconds.Increments the consecutive-failure streak if this attempt was a quick failure, or resets it if the attempt was stable.
- Parameters:
duration – How long the failed attempt lasted, in seconds.
- Returns:
A QuickFailureResult describing this attempt and whether the caller should give up.