The Python module Asyncio provides facilities to manage events, coroutines, tasks and threads, and synchronization primitives to write concurrent code. The main components and concepts of this module are:
An event loop: The Asyncio module allows a single event loop per process
Coroutines: This is the generalization of the subroutine concept. Also, a coroutine can be suspended during the execution so that it waits for external processing (some routine in I/O) and returns from the point at which it had stopped when the external processing was done.
Futures: This defines the
Future
object, such as theconcurrent.futures
module that represents a computation that has still not been accomplished.Tasks: This is a subclass of Asyncio that is used to encapsulate and manage coroutines in a parallel mode.
In this recipe, the focus is on handling events. In fact, in the context of asynchronous programming, events are very important since they are inherently asynchronous...