Modern Python writes coroutines with the keywords async and await, and runs them with the standard asyncio library. This is how high-performance web servers, chat servers and database drivers handle thousands of connections in one process.
async and await
Element
Meaning
async def f():
Defines a coroutine function; calling f() returns a coroutine object without running it
await x
Inside an async def: pause this coroutine until x (a coroutine, task or other awaitable) finishes, letting other tasks run meanwhile
asyncio.run(main())
Starts the event loop, runs the top-level coroutine main() to completion, then closes the loop
asyncio.create_task(coro)
Schedules a coroutine to run concurrently as a task; returns a Task that can be awaited later
asyncio.gather(c1, c2, ...)
Runs several awaitables concurrently and returns their results as a list
asyncio.sleep(s)
A non-blocking pause: other tasks run while this one waits (unlike time.sleep, which blocks everything)
The event loop is the scheduler: it keeps a list of tasks, runs whichever is ready, and switches when the running one reaches an await.
Key takeaways
async def creates coroutine functions; await suspends until an awaitable completes.
asyncio.run() runs the top-level coroutine on an event loop.
create_task() and gather() run coroutines concurrently.
Concurrency helps when tasks wait (I/O); use asyncio.sleep, not time.sleep.
Practice questions
Answer on paper first, then check. The explanation matters more than the letter you chose.
Question 6 · short answer
Write a program with a coroutine fetch(name, seconds) that waits for the given time and returns a message, and a main() that runs three fetches concurrently and prints their results.
Show worked answer
import asyncio, then async def fetch(name, seconds): await asyncio.sleep(seconds); return f"{name} done", then async def main(): results = await asyncio.gather(fetch("A", 1), fetch("B", 2), fetch("C", 1)); print(results), and finally asyncio.run(main()). It prints ['A done', 'B done', 'C done'] after about 2 seconds (the longest wait), instead of 4 seconds if the fetches were awaited one after another.
MCA Online notes are made for reading on screen. Open https://mcastudy.online/mcs-201/python-advanced-concepts/asynchronous-coroutines-with-asyncio/ to read this page.