Jason Brownlee's Blog, page 36

October 3, 2022

How to Get ThreadPool Worker Names in Python

You can get the name of a worker thread in the ThreadPool by calling threading.current_thread() and then accessing the “name” attribute. Worker threads are named using the default thread naming convention, although have a distinct data type compared to other threads. In this tutorial, you will discover how to get the name of worker threads […]
 •  0 comments  •  flag
Share on Twitter
Published on October 03, 2022 11:00

October 2, 2022

ThreadPool Error Callback Functions in Python

You can specify a custom error callback function when using the apply_async(), map_async(), and starmap_async() methods on the ThreadPool class via the “error_callback” argument. In this tutorial you will discover how to use error callback functions with the ThreadPool in Python. Let’s get started. Need to Use Error Callbacks with the ThreadPool The multiprocessing.pool.ThreadPool in […]
 •  0 comments  •  flag
Share on Twitter
Published on October 02, 2022 11:00

October 1, 2022

ThreadPool Callback Functions in Python

You can specify a custom callback function when using the apply_async(), map_async(), and starmap_async() functions in ThreadPool class via the “callback” argument. In this tutorial you will discover how to use callback functions with the ThreadPool in Python. Let’s get started. Need to Use Callbacks with the ThreadPool The multiprocessing.pool.ThreadPool in Python provides a pool […]
 •  0 comments  •  flag
Share on Twitter
Published on October 01, 2022 11:00

September 30, 2022

How to Configure ThreadPool map() Chunksize

You can execute tasks in batches using the “chunksize” argument when using the ThreadPool map() method. In this tutorial you will discover the chunksize argument when executing multiple tasks with the ThreadPool in Python. Let’s get started. Problem With Issuing Many Tasks to the Pool The ThreadPool allows us to issue many tasks at once. […]
 •  0 comments  •  flag
Share on Twitter
Published on September 30, 2022 12:00

September 29, 2022

How to Use ThreadPool AsyncResult

You can issue asynchronous tasks to the ThreadPool which will return an AsyncResult object. The AsyncResult provides a handle or issued tasks in the ThreadPool and can be used to check on the status of the tasks and to get task results. In this tutorial you will discover how to use the AsyncResult in Python. […]
 •  0 comments  •  flag
Share on Twitter
Published on September 29, 2022 12:00

September 28, 2022

How to Use ThreadPool map() with Multiple Arguments

The ThreadPool map() method cannot be used directly with a target function that takes multiple arguments. Instead, you need to use an alternate method like starmap() or a workaround like a wrapper function. In this tutorial you will discover how to call the ThreadPool map() function with multiple arguments indirectly and how to use alternate […]
 •  0 comments  •  flag
Share on Twitter
Published on September 28, 2022 12:00

September 27, 2022

ThreadPool apply() vs map() vs imap() vs starmap()

The ThreadPool provides many ways to issue tasks but no clear guidance on how to choose the best way to issue tasks for your application. In this tutorial you will discover: The 8 ways to issue tasks to the ThreadPool. How to use each approach to issue tasks to the ThreadPool. The differences between each […]
 •  0 comments  •  flag
Share on Twitter
Published on September 27, 2022 12:00

September 26, 2022

How to Use ThreadPool starmap_async() in Python

You can map a function that takes multiple arguments to tasks in the ThreadPool asynchronously via the starmap_async() method. In this tutorial you will discover how to issue tasks asynchronously to the ThreadPool that take multiple arguments in Python. Let’s get started. Problem with ThreadPool starmap() The multiprocessing.pool.ThreadPool in Python provides a pool of reusable […]
 •  0 comments  •  flag
Share on Twitter
Published on September 26, 2022 12:00

September 25, 2022

How to Use ThreadPool starmap() in Python

You can map() a method that takes multiple arguments to tasks in the ThreadPool via the starmap() method. In this tutorial you will discover how to issue tasks to the ThreadPool that takes multiple arguments in Python. Let’s get started. Problem with ThreadPool map() The multiprocessing.pool.ThreadPool in Python provides a pool of reusable threads for […]
 •  0 comments  •  flag
Share on Twitter
Published on September 25, 2022 12:00

September 24, 2022

How to Use ThreadPool imap_unordered() in Python

You can issue tasks to the ThreadPool one-by-one, execute them with threads, and get results in the order that tasks are completed via the imap_unordered() method. In this tutorial you will discover how to use the imap_unordered() method to issue tasks to the ThreadPool in Python. Let’s get started. Problem with ThreadPool imap() The multiprocessing.pool.ThreadPool […]
 •  0 comments  •  flag
Share on Twitter
Published on September 24, 2022 12:00