Skip to main content

Async Techniques and Examples in Python

5h 2m 11s
English
Paid

Unlock the power of Python's async and parallel programming with this comprehensive course. Designed for both beginners and experienced developers, you'll explore the full range of Python's parallel APIs, from the modern async and await keywords to advanced multiprocessing techniques. Throughout the course, you'll also delve into async Flask, thread safety, and even C-based parallelism with Cython.

Course Content Overview

Source Code and GitHub Repository

Access the course materials and source code on our dedicated GitHub repository:

github.com/talkpython/async-techniques-python-course

Course Highlights

Discover why this course stands out in the realm of parallel programming in Python. It combines foundational concepts like threading and multiprocessing with cutting-edge asynchronous programming techniques introduced in Python 3.7+.

Learn not only the core APIs, but also the best practices for applying them effectively. You'll gain insights into choosing and combining these techniques to achieve maximum performance.

What You Will Learn

  • Enhance performance and scalability through concurrency
  • Develop async code using the new async and await keywords
  • Incorporate asynchrony without extra threads or processes
  • Utilize threads to manage I/O bound tasks efficiently
  • Implement locks and thread safety mechanisms to safeguard data
  • Identify and prevent deadlocks in Python threads
  • Maximize multicore CPU usage with multiprocessing
  • Integrate thread and process APIs using execution pools
  • Achieve significant speedups with Cython and Python threads
  • Develop async view methods in Flask web applications
  • And much more

Target Audience

This course is designed for anyone looking to optimize their Python code for better performance and scalability, leveraging modern multicore CPUs. Whether you are a web developer or a data scientist, this course offers a wealth of techniques to enhance your programming capabilities.

About the Author: Talkpython

Talkpython thumbnail
Talk Python to Me is a weekly podcast hosted by Michael Kennedy. The show covers a wide array of Python topics as well as many related topics (e.g. MongoDB, AngularJS, DevOps).

Watch Online 113 lessons

This is a demo lesson (10:00 remaining)

You can watch up to 10 minutes for free. Subscribe to unlock all 113 lessons in this course and access 10,000+ hours of premium content across all courses.

View Pricing
0:00
/
#1: Course introduction
All Course Lessons (113)
#Lesson TitleDurationAccess
1
Course introduction Demo
01:27
2
Async for taking full advantage of modern CPUs
01:52
3
Topics covered
04:53
4
Student prerequisites
00:45
5
Meet your instructor
00:49
6
Video player: A quick feature tour
02:05
7
Do you have Python 3?
01:40
8
Getting Python 3
00:39
9
Recommended text editor
00:54
10
Hardware requirements
01:14
11
Get the source code
01:02
12
Async for computational speed
03:43
13
Demo: Why you need async for speed
03:55
14
An upper bound for async speed improvement
03:53
15
Async for scalability
01:50
16
Concept: Visualizing a synchronous request
03:34
17
Concept: Visualizing an asynchronous request
02:15
18
Python's async landscape
04:25
19
Why threads don't perform in Python
02:53
20
Python async landscape: asyncio
01:16
21
I/O-driven concurrency
03:51
22
Demo: Understanding basic generators
09:05
23
Demo: The producer-consumer app
03:08
24
Demo: Make the producer-consumer async
05:36
25
Demo: Make the producer-consumer async (methods)
07:17
26
Concept: asyncio
01:18
27
Performance improvements of producer consumer with asyncio
01:47
28
Faster asyncio loops with uvloop
04:38
29
Let's do some real work
01:07
30
Synchronous web scraping
03:09
31
async web scraping
09:17
32
Concept: async web scraping
01:25
33
Other async-enabled libraries
03:42
34
Python async landscape: Threads
01:07
35
Visual of thread execution
01:13
36
How to choose between asyncio and threads
02:34
37
Demo: hello threads
05:00
38
Demo: Waiting on more than one thread
03:53
39
Demo: Something productive with threads
03:10
40
Concept: Thread API
01:42
41
Concept: Tips for multiple threads
00:42
42
Cancelling threads with user input
06:02
43
Concept: Timeouts
01:22
44
Demo: Attempting to leverage multiple cores with threads
05:46
45
Python async landscape: Thread Safety landscape
00:47
46
Threads are dangerous
01:28
47
Visualizing the need for thread safety
03:35
48
Demo: An unsafe bank
05:05
49
Demo: Make the bank safe (global)
04:35
50
Demo: A missed lock in our bank (global)
01:45
51
Demo: Make the bank safe (fine-grained)
05:50
52
Demo: Breaking a deadlock
03:45
53
Concept: Basic thread safety
01:43
54
Python async landscape: multiprocessing
01:03
55
Introduction to scaling CPU-bound operations
01:52
56
Demo: Scaling CPU-bound operations with multiprocessing
04:56
57
Concept: Scaling CPU-bound operations
01:22
58
Multiprocessing return values
02:19
59
Concept: Return values
01:00
60
Python async landscape: Execution pools
01:51
61
Demo: Executor app introduction
02:22
62
Demo: Executor app (threaded-edition)
06:45
63
Demo: Executor app (process-edition)
01:47
64
Concept: Execution pools
01:43
65
Python async landscape: asyncio derivatives
01:32
66
Why do we need more libraries?
04:32
67
Introducing unsync
02:22
68
Demo: unsync app introduction
04:22
69
Demo: unsync app for mixed-mode parallelism
05:55
70
Concept: Mixed-mode parallelism with unsync
03:11
71
Introducing Trio
01:11
72
Demo: Starter code for Trio app
01:02
73
Demo: Converting from asyncio to Trio
04:54
74
Demo: Cancellation with Trio
01:57
75
Concept: Trio nurseries
01:17
76
The trio-async package
00:56
77
Python async landscape: Async web
01:21
78
Review: Request latency again
01:32
79
Demo: Introducing our Flask API
05:02
80
There is no async support for Flask
01:51
81
Demo: Introducing Quart for async Flask
01:06
82
Demo: Converting from Flask to Quart
01:30
83
Demo: Making our API async
04:39
84
Demo: An async weather endpoint
01:34
85
Concept: Flask to Quart
02:37
86
Load testing web apps with wrk
02:01
87
A note about rate limiting with external services
03:17
88
Performance results
03:33
89
Remember to run on an ASGI server
01:42
90
Python async landscape: Cython
01:32
91
C and Python are friends
01:45
92
Why Cython
03:00
93
Cython syntax compared
02:27
94
Demo: Hello Cython
05:37
95
Concept: Getting started with Cython
01:12
96
Demo: Fast threading with cython (app review)
02:47
97
Demo: Fast threading with Cython (hotspot)
01:40
98
Demo: Fast threading with Cython (conversion)
02:20
99
Demo: Fast threading with Cython (GIL-less)
04:06
100
Demo: Fast threading with Cython (int overflow issues)
02:53
101
Concept: Cython's nogil
01:25
102
The finish line
00:35
103
Review: Why async?
02:01
104
Review: asyncio
01:04
105
Review: Threads
01:19
106
Review: Thread safety
02:17
107
Review: multiprocessing
02:14
108
Review: Execution pools
01:45
109
Review: Mixed-mode parallelism
01:59
110
Review: Coordination with Trio
01:35
111
Review: Async Flask
01:18
112
Review: Cython
01:39
113
Thanks and goodbye
00:17
Unlock unlimited learning

Get instant access to all 112 lessons in this course, plus thousands of other premium courses. One subscription, unlimited knowledge.

Learn more about subscription