httk.serve.web.resources

Lifecycle management for resources owned by a site engine.

Attributes

SITE_RESOURCES_KEY

Stable global_data key through which site startup code gets resources.

CleanupCallback

Classes

Module Contents

httk.serve.web.resources.SITE_RESOURCES_KEY = 'httk_serve_resources'[source]

Stable global_data key through which site startup code gets resources.

type httk.serve.web.resources.CleanupCallback = Callable[[], None][source]
class httk.serve.web.resources.SiteResources[source]

Callbacks owned by one httk.serve.web.engine.site_engine.SiteEngine.

Site functions/init.py code can obtain this object from global_data[SITE_RESOURCES_KEY] and call register() for every persistent resource it opens. Callbacks run in reverse registration order when the httk.serve.web.engine.site_engine.SiteEngine closes. Closing is idempotent, so ASGI lifespan shutdown and an enclosing helper may both safely close the same engine.

property closed: bool[source]

Whether cleanup has started for this registry.

register(callback: CleanupCallback) None[source]

Register one synchronous callback to run during close().

Registration after close is a programming error: the callback could no longer be guaranteed to run.

close() None[source]

Run pending callbacks in LIFO order exactly once.

Every callback gets a chance to run. If cleanup fails, the first exception is re-raised after the remaining callbacks have executed; additional failures are attached as notes for diagnosis.