In this section, you’ll learn about Python concurrency including multithreading, multiprocessing, and asynchronous programming from scratch.
What you’ll learn:
- Build high-performance & responsive Python applications using concurrency techniques.
- Develop multithreaded applications using multithreading.
- Develop a program that processes tasks in parallel.
- Understand the single-threaded concurrency model.
Section 1. Multithreading
In this section, you’ll have a good understanding of processes and threads and how to develop multithreaded programs.
- Understanding Processes and Threads – help you understand the processes and threads, and the main differences between them.
- Threading – show you how to use the threading module to develop a multi-threaded application.
- Extending the Thread class – learn how to extend the Thread class to run multiple threads in a program.
- Returning values from a Thread – show you how to return values from a thread by extending the Thread class.
- Multithreading Example – build a multithreaded program that scraps stock prices.
- Daemon threads – learn about daemon threads.
- Thread Pools – guide you on managing multiple threads efficiently using the thread pool.
Section 2. Thread Synchronization Techniques
In this section, you’ll learn various techniques to synchronize between threads using a lock, event, thread-safe queue, and semaphore.
- Lock – show you how to use a lock object to control access to a shared variable safely from multiple threads.
- Event – learn how to use the threading Event to communicate between threads.
- How to stop a thread – learn how to stop a child thread from the main thread.
- Semaphore – explain the semaphore concept and how to use the Semaphore object to limit the number of threads that can access a shared resource simultaneously.
Section 3. Sharing Data Between Threads
In this section, you’ll learn various techniques to share data between threads.
- Thread-safe Queue – show you how to use a thread-safe queue to exchange data safely between multiple threads.
Section 4. Multiprocessing
In this section, you’ll learn how to utilize the multiprocessing package to develop programs that run tasks in parallel.
- Multiprocessing – show you how to run code in parallel using the multiprocessing module.
- Process Pools – learn how to manage processes more efficiently by using a process pool.
Section 5. Async I/O
In this section, you’ll how to utilize concurrency provided by the asyncio
package to improve program performance, throughput, and responsiveness.
- Understanding Event Loop – explain how the event loop works and how
asyncio
package uses the event loop to achieve a single-threaded concurrency model. - async/await – introduce to you coroutines and how to use the async and await keywords to define and pause coroutines.
- Creating tasks – learn how to create tasks and schedule them for running on the event loop.
- Canceling tasks – show you how to cancel a task using the
cancel()
method of theTask
object. - Canceling a task with a timeout – show you how to use the
asyncio.wait_for()
function to cancel a task with a timeout. - asyncio.wait() – learn about the
asyncio.wait()
function to run an iterable of awaitable objects concurrently. - Future – explain to you the Future object and awaitables.
- Running multiple tasks concurrently with gather() – run a list of tasks concurrently with the
asyncio.gather()
function.