Python ThreadPool Jump-Start
Run Your IO-Bound Functions Concurrently With Just A Few Lines Of Code
How much faster could your Python code run (if you used 100s of threads)?
The ThreadPool class provides easy-to-use thread-based concurrency for IO-bound tasks.
This is not some random third-party library, this is a class provided in the Python standard library (already installed on your system).
This is the class you need to make your code run faster.
There's just one problem. No one knows about it (or how to use it well).
Introducing: "Python ThreadPool Jump-Start". A new book designed to teach you thread pools in Python, super fast!
You will get a rapid-paced, 7-part course to get you started and make you awesome at using the ThreadPool.
- How to create thread pools and when to use them.
- How to configure thread pools including the number of threads.
- How to execute tasks with worker threads and wait for results.
- How to execute tasks in the thread pool asynchronously.
- How to execute tasks lazily and respond to results as tasks complete.
- How to handle results with callbacks and check the status of tasks.
- How to develop a port scanner that is 70x faster than the sequential version.
Each of the 7 lessons was carefully designed to teach one critical aspect of the ThreadPool, with explanations, code snippets and worked examples.
Each lesson ends with an exercise for you to complete to confirm you understood the topic, a summary of what was learned, and links for further reading if you want to go deeper.
Table of Contents
Lesson 01: Threads and Thread Pools
- What is Thread-Based Concurrency
- Thread Pools Provide Reusable Workers
- Welcome to the ThreadPool Class
- When to Use the ThreadPool
Lesson 02: Configure the ThreadPool
- Configure the ThreadPool via the Constructor
- How to Inspect the ThreadPool Default Configuration
- How to Configure the Number of Worker Threads
- How to Configure the Worker Thread Initialization
Lesson 03: Execute Tasks Concurrently and Wait
- Issue Tasks to the ThreadPool Synchronously (blocking)
- How to Execute One-Off Tasks with apply()
- How to Execute Many Tasks with map()
- How to Execute Many Tasks with Multiple Arguments
Lesson 04: Execute Tasks Concurrently and Not Wait
- Issue Tasks to the ThreadPool Asynchronously (non-blocking)
- How to Issue One-Off Tasks Asynchronously
- How to Issue Many Tasks Asynchronously
- How to Issue Tasks with Multiple Arguments Asynchronously
Lesson 05: Execute Tasks Concurrently and Responsive
- How to Overcome the Limitations of map()
- How to Issue Tasks One-by-One with imap()
- How to Get Results in Task Completion Order
Lesson 06: Callbacks and AsyncResults for Async Tasks
- How to Configure a Callback Function
- How to Manage Asynchronous Tasks with AsyncResult
- How to Check the Status of Tasks with AsyncResult
- Worked Example of Checking the Status of a Task
Lesson 07: Case Study Developing a Port Scanner
- Scan Ports One-by-One (slowly)
- Scan Ports Concurrently with ThreadPool (fast)
Stop copy-pasting code from StackOverflow answers.
Learn Python concurrency correctly, step-by-step.
Learn more about this book here:
How to Buy
- Click the "I want this!" button (in the upper right)
- Choose Credit Card or PayPal and complete the order form then click the "Pay" button.
- You will be redirected to a webpage where you can download your bundle immediately (you will also get an email with the download link, just in case you need it).
About the Author
Jason Brownlee, Ph.D. helps Python developers bring modern concurrency methods to their projects with hands-on tutorials.
Jason loves Python Concurrency. It's all he does. It’s his main thing.
- Read all the books on Python concurrency.
- Used all of the Python concurrency APIs in the standard library.
- Written 500+ tutorials and 12+ books on Python concurrency.
Learn more at SuperFastPython.com
Jason is a software engineer and research scientist with a background in artificial intelligence and high-performance computing. He has authored more than 20 technical books on machine learning and has built, operated, and exited online businesses.
See his linkedin profile here:
- Jason Brownlee on LinkedIn (follow him!)
Hi, Jason here, do you have any questions?
Contact me directly at any time about this product or Python concurrency generally. I'm here to help as best I can.
You can send an email directly to my inbox via:
You'll get a .zip download containing both ebook formats (pdf and epub) and all .py code files.