breadpool 0.0.5

Creator: coderz1093

Last updated:

Add to Cart

Description:

breadpool 0.0.5

[![Build Status](https://travis-ci.org/chamilad/breadpool.svg?branch=master)](https://travis-ci.org/chamilad/breadpool) [![Coverage Status](https://coveralls.io/repos/chamilad/breadpool/badge.svg?branch=master&service=github?dd=gg)](https://coveralls.io/github/chamilad/breadpool?branch=master)[![Documentation Status](https://readthedocs.org/projects/breadpool/badge/?version=latest)](http://breadpool.readthedocs.org/en/latest/?badge=latest)[![PyPI version](https://badge.fury.io/py/breadpool.svg)](https://badge.fury.io/py/breadpool)# BreadPool ##A Python Thread Pool and a Scheduled ExecutorBreadPool intends to simply provide implementations for a thread pool and a scheduled executor, witheasy to use interfaces and thread safety. Yes, it is a simple code to write your own implementationsfor these, however it can be a lot easier if they come in a `pip install`.## Installing BreadPoolBreadPool can be installed from the Python Package Index.```bashpip install breadpool```## ThreadPoolThe `ThreadPool` class is a simple thread pool implementation. It will initially create a set of worker threads and when assigned tasks, the worker threads will take over and execute the tasks.### Creating a ThreadPool```pythonfrom breadpool.pool import ThreadPool"""1 - number of threads to spawn2 - An identifying name to be assigned to the threads3 - daemon, True if you want the threads to immediately terminate when the main thread terminates. This is set to False by default4 - polling_timeout is the timeout for the worker threads to blockingly wait for the task queue"""thread_pool = ThreadPool(5, "CustomThreadPool", polling_timeout=1)```### Enqueuing tasksThe tasks should be implemented by extending the `AbstractRunnable` class. BreadPool provides a simple implementation of the `AbstractRunnable` class called `EasyTask` which accepts a function as the task to be executed.```pythonfrom breadpool.pool import ThreadPool, EasyTaskdef func_test(): time.sleep(random.randint(1, 5))et = EasyTask(func_test)thread_pool = ThreadPool(5, "CustomThreadPool", daemon=True)thread_pool.enqueue(et)```### Extending `AbstractRunnable`Or if your task is too complex for a simple function, you can extend the `AbstractRunnable` class and write your own task implementation.```pythonfrom breadpool.pool import AbstractRunnableclass CustomTask(AbstractRunnable): def execute(self): # task steps def __init__(self): # task initialization```## ScheduledJobExecutorThis is a simple scheduled executor for tasks of type `AbstractRunnable`. It will periodically and repeatedly execute the given task with at least the given time interval.### Usage```pythonfrom breadpool.pool import ThreadPool, ScheduledJobExecutor, EasyTaskthread_pool = ThreadPool(3, "CustomThreadPool", polling_timeout=20)counter_queue = Queue()scheduled_executor = ScheduledJobExecutor( EasyTask(lambda(l): counter_queue.put(l), "Test %s" % time.time()), thread_pool, 5, "CustomScheduledExecutor")scheduled_executor.start()....scheduled_executor.terminate()```## Python SupportBreadPool supports only Python 2.7 (for now).## LicenseBreadPool is an Apache v2.0 licensed project. ## Additional Links1. ReadTheDocs - http://breadpool.readthedocs.org/en/latest/2. PyPI - https://pypi.python.org/pypi/breadpool

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.