TPool package

Submodules

TPool.seqpool module

class TPool.seqpool.SeqPool(pool_size, target, params_list, logger=None)[source]

Bases: object

This is a thread pool to sequentially run threads

run()[source]

To run the pool :return:

TPool.wildpool module

class TPool.wildpool.WildPool(pool_size=5, logger=None)[source]

Bases: object

A flexible thread pool for managing concurrent tasks.

The WildPool class provides a thread pool that efficiently manages the execution of multiple threads concurrently. Unlike a sequential thread pool, WildPool does not guarantee the order of execution of tasks, making it particularly suited for scenarios where tasks are independent and can be processed in parallel without needing to adhere to a specific sequence.

This thread pool is designed for high-concurrency environments such as messaging queues and daemons, where managing multiple background tasks simultaneously is crucial. By limiting the number of concurrent threads to a specified maximum (pool_size), WildPool ensures that system resources are used efficiently, preventing issues like resource exhaustion or system slowdown.

Key features of WildPool include:

  • Concurrency Management: Manages a fixed number of threads, ensuring no more than the specified number of tasks run concurrently, which helps in maintaining optimal system performance.

  • Non-Sequential Execution: Tasks are executed as soon as resources are available, without guaranteeing any particular order, which is ideal for tasks that do not depend on each other.

  • Automatic Cleanup: Completed threads are automatically removed from the pool, freeing up resources for new tasks.

  • Daemon-Friendly: The pool is well-suited for daemon processes and long-running services where tasks need to be processed continuously in the background.

Parameters:
  • pool_size (int) – The maximum number of threads in the pool.

  • logger (logging.Logger, optional) – Optional custom logger. If not provided, a default logger will be used.

add_thread(thread: Thread)[source]

Add a thread to the pool to be managed and executed.

Parameters:

thread (threading.Thread) – The thread to be added to the pool.

start_worker()[source]

Start a worker thread if none is currently running.

This method ensures that only one worker thread is running to manage the threads in the pool. If a worker thread is already running, it will not start a new one.

stop()[source]

Stop the worker thread and release resources.

This method gracefully shuts down the worker thread, ensuring that all running threads are completed and resources are cleaned up.

Module contents