{ "info": { "author": "Amr Ali", "author_email": "amr.ali.cc@gmail.com", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "Intended Audience :: Information Technology", "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7" ], "description": "Adaptive Thread Pool\n====================\n\nAn adaptive thread pool implementation that offers you a configurable **minimum**\nnumber of threads to be always available during the application's lifetime.\nThis implementation adapts to the thread consumption rate by having a pool volume\nmonitoring thread increasing the number of workers to accommodate the rate of tasks\nsubmitted to the pool. Workers that sleep for a configurable period of time due to\nthe lack of tasks will be terminated.\n\nInstallation\n------------\n\nIt's trivial to install it, all you have to do is::\n\n pip install atp\n\nUsage\n-----\n\nYou will need to initialize a thread-pool before using any of the helper functions\nor passing a Task to be processed by a worker. There are two ways to use this\nlibrary, you could either initialize a global thread pool or initialize a local\nthread pool::\n\n import atp\n\n # The ``min_workers`` argument specifies the minimum number of workers in the\n # pool, the default is 2.\n # The ``stack_size`` argument specifies the stack size of each thread in KiB,\n # the default value is 512.\n\n # Initialize the global thread pool\n atp.GlobalThreadPool(min_workers = 2, stack_size = 512)\n\n # Or initialize a local thread pool\n tp = atp.ThreadPool(min_workers = 2, stack_size = 512)\n\nThere are two interfaces to pass tasks to workers. You could either create a ``Task``\nclass manually and pass it to the thread-pool or use the helper functions::\n\n import atp\n\n # Create a task manually.\n task = atp.Task(target=, success=, args=(1,2,3,),\n kwargs={'a':1, 'b':2})\n atp.GlobalThreadPool().run(task)\n\n # Run a task through helpers. Note that you can pass your own local thread-pool\n # to the helper function through the ``pool`` argument. The ``args`` and ``kwargs``\n # are the arguments and keyword arguments passed to the target functions.\n task = atp.async_call(, success=, args=(1,2,3,),\n kwargs={'a':1, 'b':2}, pool=atp.GlobalThreadPool())\n\nThere are two types of tasks you could pass to the thread pool; a one-time-run task\nand an infinite task. The former is when you need a worker to run a task only once\nbut the latter is when you need to run a task infinitely many times::\n\n import atp\n import time\n\n def print_string(string):\n print string\n\n def caps(string):\n return string.upper()\n\n task = atp.async_call(caps, 'hello world!', success=print_string)\n time.sleep(0.1) # 100ms\n\nA task that will run indefinitely will be passed an event as a first argument to\ncheck on in case you wanted it to stop::\n\n import atp\n import time\n\n result = [1]\n\n def increase(kill, arg):\n while not kill.is_set() and arg[-1] < 100:\n arg.append(arg[-1] + 1)\n\n task = atp.async_call(increase, result, infinite=True)\n time.sleep(0.1) # 100ms\n task.stop()\n assert len(result) == 100\n\nIn case of a task throwing an unhandled exception the failure callback will catch\nthe exception and wrap it in a ``Failure`` class where you can access all the\nexception's details. If the failure callback throws an unhandled error it will be\ncaught and logged::\n\n import atp\n import time\n import logging\n\n logging.getLogger().addHandler(logging.StreamHandler())\n\n def will_fail():\n throw RuntimeError(\"fake error\")\n\n def catch_fail(error):\n throw error.exception, error.message, error.traceback\n\n task = atp.async_call(will_fail, failure=catch_fail)\n time.sleep(0.1) # 100ms\n\nHacking\n-------\n\nThought of something you would like to see in ATP? You can visit the `issue tracker`_\nto check if it was reported before, and if not you are encouraged to create\nan issue or feature request first to discuss it. When you are ready to contribute\ncode or documentation fork the `code repository`_ at github_.\n\nTo get started clone your fork and setup your environment::\n\n $ git clone git@github.com:/atp.git\n $ cd atp/\n $ virtualenv venv\n $ source venv/bin/activate\n $ python setup.py develop\n\nCopying\n-------\n\nFree use of this software is granted under the terms of the GNU General Public\nLicense (GPLv3+). For details see the ``LICENSE`` file included with this\ndistribution.\n\n.. _code repository: https://github.com/amrali/atp\n.. _issue tracker: https://github.com/amrali/atp/issues\n.. _github: https://github.com/", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/amrali/atp", "keywords": null, "license": "GPLv3+", "maintainer": null, "maintainer_email": null, "name": "atp", "package_url": "https://pypi.org/project/atp/", "platform": "Posix", "project_url": "https://pypi.org/project/atp/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/amrali/atp" }, "release_url": "https://pypi.org/project/atp/0.1.0/", "requires_dist": null, "requires_python": null, "summary": "An adaptive thread pool implementation", "version": "0.1.0" }, "last_serial": 810878, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "be50cefd2703fc1a7c3ed1819bbf696e", "sha256": "42904773da2d328ace63104d9782e96ae335240c3f1af02697a802346e0d1fb2" }, "downloads": -1, "filename": "atp-0.1.0.tar.gz", "has_sig": false, "md5_digest": "be50cefd2703fc1a7c3ed1819bbf696e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 25590, "upload_time": "2013-07-08T12:56:20", "url": "https://files.pythonhosted.org/packages/02/e6/7575e985c379bdc616896597470ad50757dbdfed1cd678e1cfb088b45fd0/atp-0.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "be50cefd2703fc1a7c3ed1819bbf696e", "sha256": "42904773da2d328ace63104d9782e96ae335240c3f1af02697a802346e0d1fb2" }, "downloads": -1, "filename": "atp-0.1.0.tar.gz", "has_sig": false, "md5_digest": "be50cefd2703fc1a7c3ed1819bbf696e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 25590, "upload_time": "2013-07-08T12:56:20", "url": "https://files.pythonhosted.org/packages/02/e6/7575e985c379bdc616896597470ad50757dbdfed1cd678e1cfb088b45fd0/atp-0.1.0.tar.gz" } ] }