MCPcopy Create free account
hub / github.com/tox-dev/filelock / _poll_delay

Method _poll_delay

src/filelock/_api.py:1238–1249  ·  view source on GitHub ↗
(self, poll_interval: float, attempt: int)

Source from the content-addressed store, hash-verified

1236 time.sleep(delay)
1237
1238 def _poll_delay(self, poll_interval: float, attempt: int) -> float:
1239 # A single-file lock retries on a fixed cadence. A backend that publishes several files per acquisition sets a
1240 # cap, and then contending processes back off across a jittered, exponentially widening window instead of
1241 # colliding on every poll; poll_interval stays the floor so a lone waiter is still responsive.
1242 if not self._poll_backoff_cap:
1243 return poll_interval
1244 # Cap the exponent before doubling: under heavy contention attempt reaches the thousands, and 2**attempt would
1245 # overflow the float multiply long before the window itself stops growing past the cap.
1246 window = min(
1247 self._poll_backoff_cap, poll_interval * 2 ** min(attempt, _MAX_BACKOFF_EXPONENT)
1248 ) # pragma: needs hard-link
1249 return max(poll_interval, secrets.randbelow(int(window * 1_000_000) + 1) / 1_000_000) # pragma: needs hard-link
1250
1251 def _reconcile_failed_acquire(self, canonical: str) -> None:
1252 # An acquire that raised while still holding the native lock (a hook that failed and whose rollback could not

Callers 1

_poll_until_acquiredMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected