Jason Brownlee's Blog, page 34

October 23, 2022

ThreadPool Example in Python

The ThreadPool is a flexible and powerful thread pool for executing ad hoc tasks in an asynchronous manner. In this tutorial, you will discover a ThreadPool example that you can use as a template for your own project. Let’s dive in. How to Scan Ports on a Server One-by-One (slow) We can connect to other […]
 •  0 comments  •  flag
Share on Twitter
Published on October 23, 2022 11:00

October 22, 2022

Concurrent For-Loop With a ThreadPool in Python

You can convert a for-loop to be concurrent using the ThreadPool class. In this tutorial, you will discover how to convert a for-loop to be concurrent using the ThreadPool. Let’s get started. Need to Make For-Loop Concurrent You have a for-loop and you want to execute each iteration concurrently. This is a common situation. The […]
 •  0 comments  •  flag
Share on Twitter
Published on October 22, 2022 11:00

October 21, 2022

7 Common Errors When Using the ThreadPool

You may encounter one among a number of common errors when using the ThreadPool in Python. These errors are often easy to identify and often involve a quick fix. In this tutorial, you will discover the common errors when using the ThreadPool in Python and how to fix each in turn. Let’s get started. Common […]
 •  0 comments  •  flag
Share on Twitter
Published on October 21, 2022 11:00

October 20, 2022

5 Usage Patterns for the ThreadPool in Python

You can adopt one of the common usage patterns to get the most out of the ThreadPool in Python. In this tutorial, you will discover the common usage patterns for Python thread pools. Let’s get started. ThreadPool Usage Patterns The ThreadPool class provides a lot of flexibility for executing concurrent tasks in Python. Nevertheless, there […]
 •  0 comments  •  flag
Share on Twitter
Published on October 20, 2022 11:00

October 19, 2022

ThreadPool Best Practices in Python

It is important to follow best practices when using the ThreadPool in Python. Best practices allow you to side-step the most common errors and bugs when using threads to execute ad hoc tasks in your programs. In this tutorial, you will discover the best practices when using ThreadPool in Python. Let’s get started. ThreadPool Best […]
 •  0 comments  •  flag
Share on Twitter
Published on October 19, 2022 11:00

October 18, 2022

ThreadPool Number of Remaining Tasks

You can report the number of remaining tasks in the ThreadPool with apply_async() and a busy-wait loop, or via the imap_unordered() function. In this tutorial, you will discover how to report the number of remaining tasks in the ThreadPool. Let’s get started. Need to Report Remaining Tasks in the Pool The multiprocessing.pool.ThreadPool in Python provides […]
 •  0 comments  •  flag
Share on Twitter
Published on October 18, 2022 11:00

October 17, 2022

Why Is the ThreadPool Slower in Python?

You can make your program slower by using the ThreadPool in Python. In this tutorial, you will discover the anti-pattern for using the ThreadPool and how to avoid it on your projects. Let’s get started. ThreadPool Can Be Slower Than a For Loop The multiprocessing.pool.ThreadPool in Python provides a pool of reusable threads for executing […]
 •  0 comments  •  flag
Share on Twitter
Published on October 17, 2022 11:00

October 16, 2022

ThreadPool How to Log From Worker Processes

We can log from tasks directly in the ThreadPool by calling a function on the logging module. In this tutorial, you will discover how to log from tasks in the Python ThreadPool. Let’s get started. Need to Log From Tasks in the ThreadPool The multiprocessing.pool.ThreadPool in Python provides a pool of reusable threads for executing […]
 •  0 comments  •  flag
Share on Twitter
Published on October 16, 2022 11:00

October 15, 2022

ThreadPool Exception Handling in Python

You must handle exceptions when using the ThreadPool in Python. Exceptions may be raised when initializing worker threads, in target task threads, and in callback functions once tasks are completed. In this tutorial, you will discover how to handle exceptions in a Python ThreadPool. Let’s get started. ThreadPool Exception Handling Exception handling is an important […]
 •  0 comments  •  flag
Share on Twitter
Published on October 15, 2022 11:00

October 14, 2022

How to Get the First Result from the ThreadPool

You can get the first result from tasks in the ThreadPool either via a shared queue.Queue or by issuing tasks via the imap_unordered() function and getting the first value from the iterable. In this tutorial, you will discover how to get the first result from the ThreadPool in Python. Let’s get started. Need to Get […]
 •  0 comments  •  flag
Share on Twitter
Published on October 14, 2022 11:00