symfonic.kernel.background¶
background ¶
R7 — the run's background-work registry (RCX-8, BP-8).
The construct this module retires is the module-level _background_tasks
set: a process-wide container that outlives every run that adds to it, so a
task detached by run A is still reachable — and still running — long after A
returned. Ownership there is nobody's, which is why nothing ever waits for it
and nothing ever reports it.
Here, a task cannot exist without an owner, a purpose, and a deadline that is
no wider than the run's; it cannot be created after the run has closed; and
teardown either awaits it inside a bounded grace window or cancels it and says
so. There is one registry per :class:~symfonic.kernel.context.RequestContext
and no registry anywhere else.
BackgroundRegistry ¶
Every task one invocation spawned, owned from creation to teardown.
Source code in src/symfonic/kernel/background.py
entries
property
¶
The owner/purpose/deadline of every task still held.
drain
async
¶
Await what finishes inside the grace window, cancel and await the rest.
Closing first is what makes the window a bound: a task that spawned another task on its way out would otherwise refill the registry behind the drain, and the loop would be as long as the work chose to make it.
Source code in src/symfonic/kernel/background.py
spawn ¶
spawn(work: Coroutine[Any, Any, Any], *, owner: str, purpose: str, deadline_seconds: float | None = None) -> asyncio.Task[Any]
Register and start one unit of run-owned work.
Every rejection closes work first. A coroutine that is refused and
then left unawaited would surface as a RuntimeWarning from whatever
code happened to run next, attributing this module's refusal to an
innocent bystander.
Source code in src/symfonic/kernel/background.py
DrainReport
dataclass
¶
What draining the registry cost: work that finished, work cut, work that failed.
failures is not a subset of cancelled: a task can finish well inside
the grace window and still have raised. Reporting the two separately is what
lets teardown say "nothing was forced, but something owned by this run
broke" — a sentence the old awaited/cancelled pair could not form.