Skip to content

app

Tokamak §

Tokamak(router=None, background_task_time_limit=None, background_task_limit=1000, request_time_limit=None, cancelled_request_handler=errors.default_cancelled_request_handler, lifespan=lifespan_identity)

When using the Tokamak App instance, you should define handlers that take a tokamak.web.request.Request instance.

tokamak.web.request.Request uses in-memory-channels to: - send back a Response, and - to schedule background work.

This design aids in building in cancellation primitives (via Trio) into this library.

Parameters:

Name Type Description Default
router Optional[`tokamak.router.AsgiRouter`]

A router instance. str)`.

None
background_task_time_limit Optional[int]

Runtime Limit (in seconds) for background tasks.

None
background_task_limit int

Total limit of schedulable background tasks (backpressure will apply)

1000
request_time_limit Optional[int]

Runtime Limit (in seconds) for request handlers.

None
cancelled_request_handler Optional[Callable]

Handler for cancelled requests

errors.default_cancelled_request_handler
lifespan Callable

An async function with signature: `async def lifespan(tok: Tokamak, message_type:

lifespan_identity

__call__ async §

__call__(scope, receive, send)

A Tokamak application will be invoked here on each request

http async §

http(scope, receive, send)

HTTP request handler.

lifespan async §

lifespan(scope, receive, send)

Invoked for the lifespan activities.

This method will be run on app start and app shutdown.

process_background async §

process_background()

Method that runs to process background requests

ws async §

ws(scope, receive, send)

Websockets are currently unsupported

lifespan_identity async §

lifespan_identity(app, message_type='')

A default implementation of lifespan: the identity function

unknown_handler async §

unknown_handler(scope, receive, send)

Unknown endpoint handler (404)

Back to top