Skip to content

rinomaki/basic-async-await-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Study Async/Await in Python

This repository collects tiny, focused scripts I wrote while learning how Python's asyncio machinery fits together. Each numbered file is a self-contained example that adds one new idea on top of the previous ones, so you can read them in order or jump to the topic you care about.

Requirements

  • Python 3.10 or newer (for asyncio.run and asyncio.to_thread)
  • pip for installing extras

Optional environment setup

python -m venv .venv
source .venv/bin/activate  # Windows: .venv\\Scripts\\activate
pip install --upgrade pip
pip install aiohttp

Only 06.py needs the aiohttp dependency and an internet connection. The other scripts run with the Python standard library alone.

How to run the examples

Execute the script you want to explore with the Python interpreter:

python 01.py

Replace 01.py with any of the other files. The modules are independent, so you can run them in any order.

What each script demonstrates

  • 01.py – Smallest possible coroutine: await a sleep and see the event loop in action.
  • 02.py – Run two coroutines concurrently with asyncio.gather.
  • 03.py – Compare sequential awaits versus parallel gathering while timing both approaches.
  • 04.py – Collect coroutine return values from asyncio.gather to build a result list.
  • 05.py – Mix long-running background tasks with user input using asyncio.create_task and asyncio.to_thread.
  • 06.py – Make concurrent HTTP requests with aiohttp and inspect partial responses.

Useful references

Feel free to experiment by modifying the delays, adding error handling, or extending the patterns with your own async functions. Happy hacking!

About

Basic exercises for learning async/await in Python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages