In this lesson, you’ll see that using the concurrent.futures
module is the newer way of doing asynchronous computation in Python. It has a clean interface for working with process pools and thread pools and is only available in Python 3.
You’ll replace your multiprocessing
code with code from the concurrent.futures
module. When working with this new module, you use various classes that have Executor
in their names. There are different execution strategies for how your code is run in parallel, whether that’s across multiple processes or multiple threads within a single process, and they all follow the context manager protocol.
squeakyboots on April 27, 2021
Ha, just killed at least 30m because I named the file for the last section in the directory I’m working through this tutorial in as ‘multiprocessing.py’ so when trying to run the examples with
concurrent.futures
in a new file it failed sayingFile "C:\Users\[user]\AppData\Local\Programs\Python\Python39\lib\concurrent\futures\process.py", line 52, in <module> import multiprocessing.connection ModuleNotFoundError: No module named 'multiprocessing.connection'; 'multiprocessing' is not a package
because it was importing my own code instead of the actual multiprocessing package, which apparentlyconcurrent.futures
uses =pThat will teach me to be careful with my file naming =D
Also, the “is not a package” error is a big tell when you think you’re trying to import a package. I learned double on this video =)