concurrency#

async litestar.concurrency.sync_to_thread(fn: ~typing.Callable[[~P], ~litestar.concurrency.T], *args: ~typing.~P, **kwargs: ~typing.~P) T#

Run the synchronous callable fn asynchronously in a worker thread.

When called from asyncio, uses asyncio.loop.run_in_executor() to run the callable. No executor is specified by default so the current loop’s executor is used. A specific executor can be set using set_asyncio_executor(). This does not affect the loop’s default executor.

When called from trio, uses trio.to_thread.run_sync() to run the callable. No capacity limiter is specified by default, but one can be set using set_trio_capacity_limiter(). This does not affect trio’s default capacity limiter.

litestar.concurrency.set_asyncio_executor(executor: ThreadPoolExecutor | None) None#

Set the executor in which synchronous callables will be run within an asyncio context

litestar.concurrency.get_asyncio_executor() ThreadPoolExecutor | None#

Get the executor in which synchronous callables will be run within an asyncio context

litestar.concurrency.set_trio_capacity_limiter(limiter: trio.CapacityLimiter | None) None#

Set the capacity limiter used when running synchronous callable within a trio context

litestar.concurrency.get_trio_capacity_limiter() trio.CapacityLimiter | None#

Get the capacity limiter used when running synchronous callable within a trio context