core._async

Run async coroutines from synchronous contexts, handling both no-running-loop and already-running-loop cases.

Run async coroutines from synchronous contexts, handling both no-running-loop and already-running-loop cases.

run_sync(coro)[source]

Run an async coroutine from synchronous code.

If no event loop is running, delegates to asyncio.run(). If an event loop is already running (e.g. inside a Jupyter notebook or an existing async framework), runs the coroutine in a background thread to avoid RuntimeError.

Parameters:

coro (Coroutine[Any, Any, T]) – The coroutine to execute.

Returns:

The coroutine’s result.

Return type:

T

Functions

run_sync(coro)[source]

Run an async coroutine from synchronous code.

If no event loop is running, delegates to asyncio.run(). If an event loop is already running (e.g. inside a Jupyter notebook or an existing async framework), runs the coroutine in a background thread to avoid RuntimeError.

Parameters:

coro (Coroutine[Any, Any, T]) – The coroutine to execute.

Returns:

The coroutine’s result.

Return type:

T