Search notes:

Python standard library: asyncio

asyncio allows to create concurrent programs (async and await).

Hello world

This hello world programs was slightly adapted from Python's documentation in order to show that the type of the object that is returned by async def is a coroutine object.
import asyncio

async def async_func():

      print('Hello…')
      await asyncio.sleep(1)
      print('…World')


co_routine = async_func()

print(type(co_routine))
#
#  <class 'coroutine'>

asyncio.run(co_routine)
Github repository about-Python, path: /standard-library/asyncio/hello-world.py

Members

AbstractChildWatcher asyncio.unix_events.AbstractChildWatcher class
AbstractEventLoop asyncio.events.AbstractEventLoop class
AbstractEventLoopPolicy asyncio.events.AbstractEventLoopPolicy class
AbstractServer asyncio.events.AbstractServer class
__all__ tuple object
ALL_COMPLETED str object
all_tasks() Function
_all_tasks_compat() Function
as_completed() Function
BaseEventLoop asyncio.base_events.BaseEventLoop class
base_events Module
base_futures Module
BaseProtocol asyncio.protocols.BaseProtocol class
base_subprocess Module
base_tasks Module
BaseTransport asyncio.transports.BaseTransport class
BoundedSemaphore asyncio.locks.BoundedSemaphore class
BufferedProtocol asyncio.protocols.BufferedProtocol class
__builtins__ dict object
__cached__ str object
CancelledError asyncio.exceptions.CancelledError class
Condition asyncio.locks.Condition class
constants Module
coroutine() Function
coroutines Module
create_subprocess_exec() Function
create_subprocess_shell() Function
create_task() Function
current_task() Function
DatagramProtocol asyncio.protocols.DatagramProtocol class
DatagramTransport asyncio.transports.DatagramTransport class
DefaultEventLoopPolicy asyncio.unix_events._UnixDefaultEventLoopPolicy class
__doc__ str object
ensure_future() Function
_enter_task() Built-in function
Event asyncio.locks.Event class
events Module
exceptions Module
FastChildWatcher asyncio.unix_events.FastChildWatcher class
__file__ str object
FIRST_COMPLETED str object
FIRST_EXCEPTION str object
format_helpers Module
Future _asyncio.Future class
futures Module
gather() Function
get_child_watcher() Function
get_event_loop() Built-in function
get_event_loop_policy() Function
_get_running_loop() Built-in function
get_running_loop() Built-in function
Handle asyncio.events.Handle class
IncompleteReadError asyncio.exceptions.IncompleteReadError class
InvalidStateError asyncio.exceptions.InvalidStateError class
iscoroutine() Function
iscoroutinefunction() Function
isfuture() Function
_leave_task() Built-in function
LifoQueue asyncio.queues.LifoQueue class
LimitOverrunError asyncio.exceptions.LimitOverrunError class
__loader__ ?
Lock asyncio.locks.Lock class
locks Module
log Module
MultiLoopChildWatcher asyncio.unix_events.MultiLoopChildWatcher class
__name__ str object
new_event_loop() Function
open_connection() Function
open_unix_connection() Function
__package__ str object
__path__ list object
PidfdChildWatcher asyncio.unix_events.PidfdChildWatcher class
PriorityQueue asyncio.queues.PriorityQueue class
Protocol asyncio.protocols.Protocol class
protocols Module
Queue asyncio.queues.Queue class
QueueEmpty asyncio.queues.QueueEmpty class
QueueFull asyncio.queues.QueueFull class
queues Module
ReadTransport asyncio.transports.ReadTransport class
_register_task() Built-in function
run() Function
run_coroutine_threadsafe() Function
runners Module
SafeChildWatcher asyncio.unix_events.SafeChildWatcher class
SelectorEventLoop asyncio.unix_events._UnixSelectorEventLoop class
selector_events Module
Semaphore asyncio.locks.Semaphore class
SendfileNotAvailableError asyncio.exceptions.SendfileNotAvailableError class
set_child_watcher() Function
set_event_loop() Function
set_event_loop_policy() Function
_set_running_loop() Built-in function
shield() Function
sleep() Function
__spec__ ?
sslproto Module
staggered Module
start_server() Function
start_unix_server() Function
StreamReader asyncio.streams.StreamReader class
StreamReaderProtocol asyncio.streams.StreamReaderProtocol class
streams Module
StreamWriter asyncio.streams.StreamWriter class
subprocess Module
SubprocessProtocol asyncio.protocols.SubprocessProtocol class
SubprocessTransport asyncio.transports.SubprocessTransport class
sys Module
Task _asyncio.Task class
tasks Module
ThreadedChildWatcher asyncio.unix_events.ThreadedChildWatcher class
threads Module
TimeoutError asyncio.exceptions.TimeoutError class
TimerHandle asyncio.events.TimerHandle class
to_thread() Function
Transport asyncio.transports.Transport class
transports Module
trsock Module
unix_events Module
_unregister_task() Built-in function
wait() Function
wait_for() Function
wrap_future() Function
WriteTransport asyncio.transports.WriteTransport class

See also

The def statement
types.coroutine allows interoperability between existing generator-based coroutines in asyncio and native coroutines introduced by PEP 492.
concurrent.futures
PEPs
aio-libs (github) is the set of ayncio-based libraries (allegedly built with high quality) and includes, among others:

Index