{ "info": { "author": "Chamila de Alwis", "author_email": "cs@chamiladealwis.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Natural Language :: English", "Operating System :: Unix", "Programming Language :: Python :: 2.7", "Topic :: Software Development :: Libraries" ], "description": "[![Build Status](https://travis-ci.org/chamilad/breadpool.svg?branch=master)](https://travis-ci.org/chamilad/breadpool) \n[![Coverage Status](https://coveralls.io/repos/chamilad/breadpool/badge.svg?branch=master&service=github?dd=gg)](https://coveralls.io/github/chamilad/breadpool?branch=master)\n[![Documentation Status](https://readthedocs.org/projects/breadpool/badge/?version=latest)](http://breadpool.readthedocs.org/en/latest/?badge=latest)\n[![PyPI version](https://badge.fury.io/py/breadpool.svg)](https://badge.fury.io/py/breadpool)\n\n# BreadPool \n##A Python Thread Pool and a Scheduled Executor\n\nBreadPool intends to simply provide implementations for a thread pool and a scheduled executor, with\neasy to use interfaces and thread safety. Yes, it is a simple code to write your own implementations\nfor these, however it can be a lot easier if they come in a `pip install`.\n\n## Installing BreadPool\nBreadPool can be installed from the Python Package Index.\n\n```bash\npip install breadpool\n```\n\n## ThreadPool\nThe `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.\n\n### Creating a ThreadPool\n\n```python\nfrom breadpool.pool import ThreadPool\n\n\"\"\"\n1 - number of threads to spawn\n2 - An identifying name to be assigned to the threads\n3 - daemon, True if you want the threads to immediately terminate when the main thread terminates. This is set to False by default\n4 - polling_timeout is the timeout for the worker threads to blockingly wait for the task queue\n\"\"\"\nthread_pool = ThreadPool(5, \"CustomThreadPool\", polling_timeout=1)\n\n```\n\n### Enqueuing tasks\nThe 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.\n\n```python\nfrom breadpool.pool import ThreadPool, EasyTask\n\ndef func_test():\n time.sleep(random.randint(1, 5))\net = EasyTask(func_test)\nthread_pool = ThreadPool(5, \"CustomThreadPool\", daemon=True)\nthread_pool.enqueue(et)\n```\n\n### Extending `AbstractRunnable`\nOr if your task is too complex for a simple function, you can extend the `AbstractRunnable` class and write your own task implementation.\n\n```python\nfrom breadpool.pool import AbstractRunnable\n\nclass CustomTask(AbstractRunnable):\n def execute(self):\n # task steps\n\n def __init__(self):\n # task initialization\n\n```\n\n## ScheduledJobExecutor\nThis 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.\n\n### Usage\n\n```python\nfrom breadpool.pool import ThreadPool, ScheduledJobExecutor, EasyTask\n\nthread_pool = ThreadPool(3, \"CustomThreadPool\", polling_timeout=20)\ncounter_queue = Queue()\nscheduled_executor = ScheduledJobExecutor(\n EasyTask(lambda(l): counter_queue.put(l), \"Test %s\" % time.time()),\n thread_pool,\n 5,\n \"CustomScheduledExecutor\")\n\nscheduled_executor.start()\n....\nscheduled_executor.terminate()\n```\n\n## Python Support\nBreadPool supports only Python 2.7 (for now).\n\n## License\nBreadPool is an Apache v2.0 licensed project. \n\n## Additional Links\n\n1. ReadTheDocs - http://breadpool.readthedocs.org/en/latest/\n2. PyPI - https://pypi.python.org/pypi/breadpool", "description_content_type": null, "docs_url": "https://pythonhosted.org/breadpool/", "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/chamilad/breadpool", "keywords": "python thread pool scheduled executor", "license": "Apache v2.0", "maintainer": null, "maintainer_email": null, "name": "breadpool", "package_url": "https://pypi.org/project/breadpool/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/breadpool/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/chamilad/breadpool" }, "release_url": "https://pypi.org/project/breadpool/0.0.5/", "requires_dist": null, "requires_python": null, "summary": "A Python Thread Pool and a Scheduled Executor", "version": "0.0.5" }, "last_serial": 1855416, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "ffe5f771cbc20e6a9602b5363f02cc5f", "sha256": "fd0c601d5248cf31d8d3a74dd03693d0dad1bc178ca2a7428efc30ea5d8c389e" }, "downloads": -1, "filename": "breadpool-0.0.1.tar.gz", "has_sig": false, "md5_digest": "ffe5f771cbc20e6a9602b5363f02cc5f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3515, "upload_time": "2015-12-09T17:57:52", "url": "https://files.pythonhosted.org/packages/f1/83/7e3771d062f43c6b70c27e191595ad94dd4a8728ee7d07a29e19766f6287/breadpool-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "5ccad5b6939b76698398e0a8dd0a68e2", "sha256": "9f1280166d5438ace8a30da3c4bbeca76adca6a83162dd05b38376d4a52eae67" }, "downloads": -1, "filename": "breadpool-0.0.2.tar.gz", "has_sig": false, "md5_digest": "5ccad5b6939b76698398e0a8dd0a68e2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3481, "upload_time": "2015-12-09T18:03:52", "url": "https://files.pythonhosted.org/packages/2c/99/952dbf3f17abe1ad2cc677132871f7e7864fde90ac54dbf3605eac4de574/breadpool-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "d5917aaddfaf9fa72f14808218ce4e0f", "sha256": "815c966cae157dcfa1c9b7a132885e9776934501e06f8cbae8e2ae9b8271e952" }, "downloads": -1, "filename": "breadpool-0.0.3.tar.gz", "has_sig": false, "md5_digest": "d5917aaddfaf9fa72f14808218ce4e0f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12153, "upload_time": "2015-12-09T20:21:07", "url": "https://files.pythonhosted.org/packages/8a/a0/d9d0cda38f4da7cdf46260b63e826774d6cd7d7f42bda2b64d5a79b3b136/breadpool-0.0.3.tar.gz" } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "bc506f312d334b4dc8925abf2f8e3413", "sha256": "8de1c9dac167afdc7cb55da5abdc4764e7f6415cc13c70539791ca815408c79e" }, "downloads": -1, "filename": "breadpool-0.0.4.tar.gz", "has_sig": false, "md5_digest": "bc506f312d334b4dc8925abf2f8e3413", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12387, "upload_time": "2015-12-10T12:33:27", "url": "https://files.pythonhosted.org/packages/bf/3e/8580e18eb023215af9120a10a4465e073c265993b1b910e9c2073d0a5679/breadpool-0.0.4.tar.gz" } ], "0.0.5": [ { "comment_text": "", "digests": { "md5": "ac5d39d31f30b85d5a7fbf0846e0143f", "sha256": "da8db91b44f6e5949e2bcc9adf2ba1a661182aa07218b2aa2966b57cabab0555" }, "downloads": -1, "filename": "breadpool-0.0.5.tar.gz", "has_sig": false, "md5_digest": "ac5d39d31f30b85d5a7fbf0846e0143f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12385, "upload_time": "2015-12-10T12:56:37", "url": "https://files.pythonhosted.org/packages/74/81/13ff989b9dd1fe9cb5c94f977da1bd2d6c833a0b0c4b947eafedfe60039d/breadpool-0.0.5.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "ac5d39d31f30b85d5a7fbf0846e0143f", "sha256": "da8db91b44f6e5949e2bcc9adf2ba1a661182aa07218b2aa2966b57cabab0555" }, "downloads": -1, "filename": "breadpool-0.0.5.tar.gz", "has_sig": false, "md5_digest": "ac5d39d31f30b85d5a7fbf0846e0143f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12385, "upload_time": "2015-12-10T12:56:37", "url": "https://files.pythonhosted.org/packages/74/81/13ff989b9dd1fe9cb5c94f977da1bd2d6c833a0b0c4b947eafedfe60039d/breadpool-0.0.5.tar.gz" } ] }