breadpool package¶
Subpackages¶
Submodules¶
breadpool.pool module¶
BreadPool intends to simply provide implementations for a thread pool and a scheduled executor, with easy to use interfaces and thread safety. Yes, it is a simple code to write your own implementations for these, however it can be a lot easier if they come in a pip install.
-
class
breadpool.pool.
AbstractRunnable
[source]¶ Bases:
object
The tasks that should be executed using the ThreadPool or the ScheduledJobExecutor should be of a sub class of AbstractRunnable. Extend AbstractRunnable and write the task implementation inside the execute() method.
Take a look at the EasyTask implementation of AbstractRunnable for an example.
-
class
breadpool.pool.
EasyTask
(function, *args, **kwargs)[source]¶ Bases:
breadpool.pool.AbstractRunnable
This is an implementation of the AbstractRunnable class which accepts a function to be executed.
EasyTask allows to easily submit functions as runnable tasks to the ThreadPool or the ScheduledJobExecutor.
-
class
breadpool.pool.
ScheduledJobExecutor
(task, thread_pool, delay, name)[source]¶ Bases:
threading.Thread
A Scheduled executor which periodically executes a given task. This should be given a thread pool to work on. When a task is submitted to the scheduled task, it will repeatedly, periodically execute that task using the provided thread pool.
-
class
breadpool.pool.
ThreadPool
(size, name, daemon=False, polling_timeout=60)[source]¶ Bases:
object
The ThreadPool class offers a simple Thread pool implementation for Python. It uses Python’s Queues to coordinate tasks among a set of worker threads. The specified number of threads are created when the thread pool is created, and is maintained so that they do not increase more than that number.
-
enqueue
(task)[source]¶ Adds the specified task to the task queue for a worker thread to start working on it. If any free worker threads are waiting on the task queue, it will immediately pick up this task.
Parameters: task – The task to be added to the task queue. Returns:
-