Explain Python asyncio code

Paste async Python and Vibe explains what runs at the same time and what waits: what async def, await, gather and a timeout do, and which line quietly stops everything else.

fetch_all.py

Up to 1,500 characters (about 60 lines). Your code is sent to Unvibe and Anthropic to write the explanation. Don't paste keys or passwords. Common key formats are refused.

Vibe23 lines selected

Press Explain it for the sample, or paste your own code first.

What this Python asyncio sample shows

async def and await
async def makes fetch a coroutine function: calling it only creates a coroutine object, and nothing inside runs until something awaits it. Called without await, fetch("users", 1.0) printed nothing, and Python warned coroutine 'fetch' was never awaited. await asyncio.sleep(...) pauses this one fetch and lets the others run in the meantime.
gather
asyncio.gather started all 3 at once: users, orders and reports each printed 0.0s start. Users finished at 1.0s and orders at 2.0s, and the whole script took 3.0s. Awaiting the same 3 one after another took 6.0s, because each one started only when the one before had finished.
timeouts
asyncio.wait_for(..., timeout=3.0) canceled reports at 3.0s, 2 seconds before its 5 second sleep would have ended, and its result came back as TimeoutError(). return_exceptions=True is why the other 2 results survived. Without it, gather raised the TimeoutError at 3.0s and main never got the users and orders results.
blocking calls
When users used time.sleep(1.0) instead of await asyncio.sleep(1.0), orders and reports didn't start until 1.0s, and the script took 4.0s instead of 3.0s. time.sleep holds the whole program, so nothing else can run until it returns. A 4 second time.sleep in one task held back the other task, so its 3 second timeout started at 4.0s and fired at 7.0s.

Good to know

  • Run with Python 3.14.7. The script printed users and orders done at 1.0s and 2.0s, then 'users: 1.0s', 'orders: 2.0s', TimeoutError() and total 3.0s. Every timing above is from the same script or a variant of it, rounded to 0.1s.
  • asyncio.TaskGroup, the newer way to run tasks together, stops the rest when one fails: with reports timing out at 0.5s, it canceled orders at 0.5s too and raised an ExceptionGroup. gather without return_exceptions did not: main got the error at 0.5s, and orders still finished at 2.0s.

Watch out: One ordinary blocking call inside async code slows every task, with no error. time.sleep, requests.get or a heavy loop in an async def holds the program the same way time.sleep(1.0) held users here: the other loads waited, and a timeout couldn't fire until the call returned. In async code, use the awaitable version, such as await asyncio.sleep or an async HTTP client, or hand the blocking call to asyncio.to_thread.

Explain Python asyncio code beside your editor

Unvibe is a free app for Mac and Windows. In the app there is no pasting: select code in any app and press Control+U (Ctrl+Alt+U on Windows).

Install on Mac

curl -fsSL https://unvibe.site/install.sh | bash

Paste into Terminal. Unvibe isn't notarized by Apple yet, so this is the smooth path.

Opening the .dmg the first time
  1. Open the .dmg and drag Unvibe to Applications.
  2. Open it once; macOS says it can't verify it. Click Done.
    macOS dialog: Unvibe Not Opened, with Done and Move to Trash
    Real screen, macOS 15
  3. System Settings › Privacy & Security › Open Anyway. Confirm, then enter your Mac password. The button shows for about an hour after you try to open Unvibe.
    macOS Privacy & Security, Security section: Unvibe was blocked to protect your Mac, with the Open Anyway button
    Real screen, macOS 15

The Terminal line checks the download against the published SHA-256 and Unvibe's self-signed signature before it installs anything. More help with the first open