Some text some message..
Back import asyncio: write asynchronous (non-blocking) programs 07 Oct, 2025

import asyncio


🎯 1️⃣ What it Means

💡 asyncio is a Python library that helps you write asynchronous (non-blocking) programs.

In simple terms — it lets your program do multiple tasks at once without waiting for each to finish one by one.


⚙️ 2️⃣ Imagine This

Let’s say you have 3 tasks:
🍜 Boil noodles
🥕 Chop vegetables
🔥 Heat sauce

Normally (synchronous):
1️⃣ Boil noodles → wait till done
2️⃣ Then chop veggies → wait
3️⃣ Then heat sauce

Total time = ⏳ long!


With asyncio (asynchronous):
All three start together — while noodles boil, you chop veggies, and heat the sauce 🔥😎

✅ Saves time
✅ Makes program faster
✅ Perfect for web servers, API calls, and I/O-heavy tasks


🧩 3️⃣ Why We Use import asyncio

Because it’s part of Python’s standard library — no need to install anything extra!
By importing it, you gain access to:

  • async def → defines an asynchronous function

  • await → waits for async tasks to finish

  • asyncio.run() → runs your async program


🧠 4️⃣ Tiny Example

import asyncio

async def greet():
    print("👋 Hello Abhi!")
    await asyncio.sleep(2)
    print("🌞 How are you today?")

asyncio.run(greet())

🌀 What happens?

  1. Prints “👋 Hello Abhi!” instantly

  2. Waits for 2 seconds (non-blocking)

  3. Prints “🌞 How are you today?”

Meanwhile, Python could be doing other async tasks!


💬 5️⃣ In Short

Concept Meaning Emoji
asyncio Async programming library
async def Defines async function 🧠
await Pause and resume later ⏸️▶️
asyncio.run() Runs the async program 🚀