Flashcards for Asynchronous Programming (Chapter 5)
Flashcard 1
**Question:** What is the purpose of the concurrent.futures module?
**Answer:** The concurrent.futures module provides a level of abstraction on threads by
modeling them as asynchronous functions. It includes classes such as Executor for executing
calls asynchronously and Future to encapsulate the execution of a callable.
Flashcard 2
**Question:** What is the asynchronous approach to task execution?
**Answer:** The asynchronous approach executes various tasks that intersect along the
timeline under a single flow of control. Tasks are suspended and resumed over time,
alternating with the execution of other tasks, without running on multiple threads.
Flashcard 3
**Question:** What are the main components of asyncio?
**Answer:** The main components of asyncio include Event Loop (manages task
distribution), Coroutines (suspendable computations), Futures (represent unfinished
tasks), and Tasks (manage coroutines).
Flashcard 4
**Question:** What is the sequence of task execution in an event loop?
**Answer:** In an event loop, tasks are registered, queued, and executed one at a time by
invoking their handlers, ensuring control passes to the next task only when the current
handler finishes.
Flashcard 5
**Question:** How does the yield from syntax work in coroutines?
**Answer:** The yield from syntax allows a coroutine to wait for another coroutine or
future to complete. The result of the awaited task is then propagated back to the waiting
coroutine.
Flashcard 6
**Question:** What is an argument in the context of a coroutine?
**Answer:** An argument in a coroutine is a parameter passed to define task-specific
behavior. For example, in the factorial coroutine, the number parameter determines the
factorial computation range.