schedr.runner.coroutines

Runs an async def task’s coroutine in the attempt’s own event loop.

Imported only for such a task: asyncio is slow to import, and most tasks don’t need it. The loop is uvloop’s whenever this interpreter can import it, however it was installed (decision 316; schedr[uvloop] is one way); otherwise asyncio’s own.

schedr.runner.coroutines.loop_factory()

What makes the event loop: uvloop’s if it is installed.

Returns:

Its factory; None for asyncio’s own.

Return type:

Callable[[], AbstractEventLoop] | None

schedr.runner.coroutines.run_coroutine(coroutine)

Runs a task’s coroutine until it ends, in a new event loop.

SIGTERM cancels the coroutine, so its finally and async with blocks run within the grace time; the process then ends by that signal, as a sync task’s does at once, whatever the coroutine did with the cancellation. A loop blocked by sync code can’t run them, and is killed when the grace time ends. Background tasks still running at the end are cancelled, as asyncio.run does. The task’s log says which loop it ran on.

Parameters:

coroutine (Coroutine[object, object, T]) – The coroutine.

Returns:

What it returned.

Raises:

RuntimeError – When the coroutine was cancelled by something other than the stop signal.

Return type:

T