Using Threads
Explore how to implement threads in Python to run functions concurrently across CPUs. Understand thread management, including daemon threads and join methods, while recognizing performance constraints imposed by Python's Global Interpreter Lock. Gain practical insights into running multiple threads for parallel tasks, improving application responsiveness in CPU scaling contexts.
We'll cover the following...
What are threads?
Threads in Python are a good way to run a function concurrently with other functions. If your system does not support multiple processors, the threads will be executed one after another as scheduled by the operating system. However, if multiple CPUs are available, threads could be scheduled on multiple processing units, once again as determined by the operating system.
By default, there is only one thread, the main thread, and it is the thread that runs your Python application. To start another thread, Python provides the threading module.
To run the following code snippet, press the Run button and enter the command
python2 threading-start.py. ...