May 2021
Intermediate to advanced
142 pages
3h 37m
English
Now that you’ve seen how to run code in threads or processes using ThreadPoolExecutor and ProcessPoolExecutor, which should you choose to use at any given time?
Let’s revisit the table we saw earlier in this chapter:
| Module | Paradigm | Object | Share Memory? | Restricted by GIL? |
|---|---|---|---|---|
| threading | threads | Thread | Yes | Yes |
| multiprocessing | processes | Process | No | No |
The two primary differences between Thread and Process objects have to do with how memory is shared and how something called the GIL restricts performance.
First, we’ll discuss memory sharing in Thread and Process objects.
In general, if you use the Thread object from the threading module, your “threaded” code will ...