graflo.architecture.query.timeout¶
Time limits on reads: the error a backend raises, and one deadline per call.
A backend that declares supports_query_timeout hands the limit to its
database or driver, which cancels the work; the driver's own timeout error is
translated into :class:QueryTimeoutError. A call made of several reads (a
breadth-first walk, a chunked lookup) spends one :class:Deadline across all of
them: each read is given what is left, and none starts once nothing is.
Classes¶
Deadline
¶
One time limit spent across every read of a call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout_s
|
float | None
|
Seconds the whole call may take; |
required |
clock
|
Callable[[], float] | None
|
Monotonic clock in seconds; :func: |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
As :func: |
Source code in graflo/architecture/query/timeout.py
Attributes¶
bounded
property
¶
Whether the call has a limit at all.
timeout_s = check_timeout(timeout_s)
instance-attribute
¶
Methods:¶
__init__(timeout_s, *, clock=None)
¶
Source code in graflo/architecture/query/timeout.py
kwargs()
¶
remaining()
¶
Seconds left for the next read; None when there is no limit.
Raises:
| Type | Description |
|---|---|
QueryTimeoutError
|
Nothing is left, so no further read may start. |
Source code in graflo/architecture/query/timeout.py
spent()
¶
Report a timeout raised inside the block as this deadline's.
A read handed the remainder of the deadline times out on that remainder; the caller set the whole limit, so that is the one named.
Source code in graflo/architecture/query/timeout.py
QueryTimeoutError
¶
Bases: TimeoutError
A read ran past its time limit and the database stopped it.
Attributes:
| Name | Type | Description |
|---|---|---|
timeout_s |
The limit, in seconds, that was exceeded. |
Source code in graflo/architecture/query/timeout.py
TimeoutKwargs
¶
Bases: TypedDict
The timeout_s keyword of a read, present only when there is a limit.
Source code in graflo/architecture/query/timeout.py
Functions:¶
check_timeout(timeout_s)
¶
timeout_s if it is a usable limit, None for none.
Raises:
| Type | Description |
|---|---|
ValueError
|
The limit is not a finite number of seconds above zero. Several drivers read zero as "no limit", so it is refused rather than passed on. |
Source code in graflo/architecture/query/timeout.py
timeout_kwargs(timeout_s)
¶
{"timeout_s": timeout_s}, or nothing when there is no limit.
Passing the keyword only when it is set keeps a call without a limit exactly as it was.