Sling Academy
Home/Python/Python Asynchronous Programming Tutorials

Python Asynchronous Programming Tutorials

Asynchronous programming in Python allows for concurrent execution of tasks, enabling non-blocking operations and efficient utilization of resources. It utilizes async and await keywords to manage and coordinate asynchronous operations, such as network requests, without blocking the program’s execution.

This series of tutorials will provide explanations and practical code examples about asynchronous programming and tasks related to it in Python, in order from basic to advanced, from simple to complex.

1 Python asyncio: What are coroutines and event loops?

2 Python asyncio.run() function (with examples)

3 Python asyncio.wait_for() function (with examples)

4 Python: Using async/await with loops (for & while loops)

5 Python asyncio.sleep() function (with examples)

6 Python asyncio.create_task() function (with examples)

7 Python async/await and timeouts (with examples)

8 Python asyncio.loop.run_until_complete() function (with examples)

9 Python asyncio.gather() function (with examples)

10 Python: Handling exceptions when using async/await

11 Python: Using the result returned by an async function (4 examples)

12 Python: How to Define and Call Asynchronous Functions

13 Python asyncio.Semaphore class (with examples)

14 Python asyncio.Runner() context manager (with examples)

15 Python: Running a function periodically with asyncio

16 Python asyncio.wait() function (with examples)

17 Python asyncio.as_completed() function (with examples)

18 Python asyncio.Queue class (with 3 examples)

19 Python: Using the “yield” keyword with async/await (3 examples)

20 Python asyncio.run_coroutine_threadsafe() function (with examples)

21 Python: Using async/await with class methods (3 examples)

22 Python: Defining a class with an async constructor (3 ways)

23 Python asyncio.loop.run_in_executor() method (3 examples)

24 Python asyncio: Run a task at a certain time every day (2 examples)

25 Python asyncio.loop.create_server() method (with examples)

26 Python: Add a coroutine to an already running event loop

27 Understanding thread-safe in Python: Explained with examples

28 Python Stream: asyncio.open_connection() function explained (with examples)

29 Python Steam: How to start a socket server with asyncio.start_server()

30 2 Ways to Create a Future Object in Python

31 Python asyncio: Adding schedule callbacks to a Future

32 Python asyncio.StreamReader: A Practical Guide (with examples)

33 Python asyncio.StreamWriter: A Practical Guide (with examples)

34 Python: How to return a value from a Future

35 Python sqlite3: Using dataclass to validate data before inserting

36 Python: How to convert a Future to a Task – Examples

37 Python: Convert callback-based functions to async functions

38 How to run Python code in multi-core CPUs using asyncio

39 Python asyncio: How to download a list of files sequentially

40 Python asyncio: How to download a list of files in parallel

41 Python asyncio: How to download a large file and show progress (percentage)

42 Python: How to create your own asyncio TCP server (and test it using cURL)

43 Python: How to type hint asynchronous functions

44 Python: When you should NOT use asyncio

45 Python: How to define and call async generator functions

46 Understanding asyncio.Lock in Python: Explained with examples

47 Python: Why you cannot call asyncio.run() multiple times and what are the alternatives

48 Understanding asyncio.Barrier in Python: Explained with examples

49 Fixing Python aiohttp Error ‘Could Not Build Wheels’

50 Exploring asyncio.Event in Python (through examples)

51 Python asyncio program to run a shell command and get the result

52 Python Asyncio RuntimeError: Event Loop is Closed – Fixing Guide

53 Python asyncio: What is a subprocess and how to use it

54 Python: A closer look at asyncio.create_subprocess_exec() function

55 Python Asyncio RuntimeError: Cannot Close a Running Event Loop

56 A list of popular Python libraries that use asyncio

57 Python asyncio: How to control and communicate with subprocesses

58 Python asyncio: How to stop/kill a child process

59 Python asyncio: How to list all tasks that are not done

60 Python asyncio: How to prevent a task from being canceled

61 Python: Using asyncio.timeout_at() to set a ‘deadline’ for a task

62 Python asyncio: How to set name for a task to get it later

63 Python asyncio: How to run a function in a separate thread

64 Python asyncio: How to determine the currently running task

65 Python asyncio: How to know if a task is cancelled

66 Python asyncio: Determine the current thread where the event loop is running

67 Python: Using asyncio.TaskGroup to manage a group of tasks

68 Python asyncio priority queue: Running tasks in a specific order

69 Python asyncio: Display a loading indicator in the terminal while waiting for a task to complete

70 Python error: asyncio.run() cannot be called from a running event loop

71 Python asyncio: How to limit the number of concurrent tasks

72 Python: Using async functions with the ‘WITH’ statement

73 Solving Python asyncio error: object dict can’t be used in ‘await’ expression

74 Python: How to clean up resources when an event loop is interrupted

75 Python: Using ‘async for’ to iterate over an asynchronous iterator

76 Python: Using ‘async with’ to manage resources in an asynchronous context

77 Python asyncio: How to simulate JavaScript promise chaining

78 Python RuntimeWarning: Coroutine Was Never Awaited [Solved]

79 Python asyncio – Task Wrapping Examples (basic to advanced)

80 Python: Handling asyncio.exceptions.CancelledError gracefully

81 Python SyntaxError: ‘await’ outside async function