seldon-runtime 0.1.1.dev0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,51 @@
1
+ """Request-deadline context and the serving/compiler admission failure types."""
2
+
3
+ import asyncio
4
+ from contextlib import contextmanager
5
+ from contextvars import ContextVar
6
+
7
+
8
+ class ServingCapacity(ValueError):
9
+ """Serving admission refused before any provider dispatch: nothing was sent.
10
+
11
+ Message stays ``provider_capacity`` for existing error surfaces. The distinct
12
+ type lets the serving executor fall back; compiler code never raises it.
13
+ """
14
+
15
+ def __init__(self):
16
+ super().__init__("provider_capacity")
17
+
18
+
19
+ # Context-local so forks, judges and nested candidate/fallback calls inherit the
20
+ # enclosing deadline without changing the public executor/provider interface.
21
+ _deadline = ContextVar("compiler_admission_deadline", default=None)
22
+
23
+
24
+ @contextmanager
25
+ def admission_deadline(deadline):
26
+ enclosing = _deadline.get()
27
+ value = min(deadline, enclosing) if enclosing is not None else deadline
28
+ token = _deadline.set(value)
29
+ try:
30
+ yield value
31
+ except TimeoutError as exc:
32
+ # Admission proves nothing was dispatched. If the executor deadline
33
+ # interrupts its asynchronous cleanup, asyncio wraps the cancellation
34
+ # and otherwise hides that retryable outcome behind a generic timeout.
35
+ # Restore only this direct chain; provider timeouts and caller-driven
36
+ # cancellation retain their original meaning.
37
+ cancellation = exc.__cause__
38
+ capacity = getattr(cancellation, "__context__", None)
39
+ if isinstance(cancellation, asyncio.CancelledError) and isinstance(
40
+ capacity, AdmissionFailure
41
+ ):
42
+ raise type(capacity)(capacity.admission) from None
43
+ raise
44
+ finally:
45
+ _deadline.reset(token)
46
+
47
+
48
+ class AdmissionFailure(ValueError):
49
+ def __init__(self, diagnostics):
50
+ super().__init__("provider_capacity")
51
+ self.admission = diagnostics