Chapter 3. Working with Threads in Python
We have seen an example of threads being used in concurrent and parallel programming in Example 2 in Chapter 1. In this chapter, you will be introduced to the formal definition of a thread, as well as the threading
module in Python. We will cover a number of ways to work with threads in a Python program such as creating new threads, synchronizing threads, and working with multi-threaded priority queues via specific examples. Chapter 3 also discusses the concepts of a lock in thread synchronization, and we will be implementing a lock-based multi-threaded application to better understand the benefits of thread synchronization.
The following topics will be covered in this chapter:
- The concept of a thread in the context of concurrent programming in computer science
- The basic API of the
threading
module in Python - How to create a new thread via the
threading
module - The concept of a lock and how to use different locking mechanisms to synchronize threads
- The concept...