Low-level API Index

This page lists all low-level asyncio APIs.

Obtaining the Event Loop

asyncio.get_running_loop()

The preferred function to get the running event loop.

asyncio.get_event_loop()

Get an event loop instance (running or current via the current policy).

asyncio.set_event_loop()

Set the event loop as current via the current policy.

asyncio.new_event_loop()

Create a new event loop.

Examples

Event Loop Methods

See also the main documentation section about the Event Loop Methods.

Lifecycle

loop.run_until_complete()

Run a Future/Task/awaitable until complete.

loop.run_forever()

Run the event loop forever.

loop.stop()

Stop the event loop.

loop.close()

Close the event loop.

loop.is_running()

Return True if the event loop is running.

loop.is_closed()

Return True if the event loop is closed.

await loop.shutdown_asyncgens()

Close asynchronous generators.

Debugging

loop.set_debug()

Enable or disable the debug mode.

loop.get_debug()

Get the current debug mode.

Scheduling Callbacks

loop.call_soon()

Invoke a callback soon.

loop.call_soon_threadsafe()

A thread-safe variant of loop.call_soon().

loop.call_later()

Invoke a callback after the given time.

loop.call_at()

Invoke a callback at the given time.

Thread/Process Pool

await loop.run_in_executor()

Run a CPU-bound or other blocking function in a concurrent.futures executor.

loop.set_default_executor()

Set the default executor for loop.run_in_executor().

Tasks and Futures