{ "info": { "author": "Kevin L. Mitchell", "author_email": "klmitch@mit.edu", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Utilities" ], "description": "====================\nIterative Work Queue\n====================\n\n.. image:: https://travis-ci.org/klmitch/workq.svg?branch=master\n :target: https://travis-ci.org/klmitch/workq\n\nIn programming, there are some problems with recursive algorithms.\nOne of them is the stack: each recursion adds a new frame to the\nstack. This can be mitigated using tail recursion, but tail recursion\nisn't always possible. A second problem is loops: consider loading a\nseries of files which contain an \"include\" instruction, where one of\nthe files contains an \"include\" for itself or for another file which\ncontains an \"include\" for it.\n\nOne good solution for these problems is to recast the recursive\nalgorithm as an iterative one. A ``WorkQueue`` is a tool for doing\nexactly this; it is an iterator for work items, where work items may\nbe added to the queue during iteration. A ``WorkQueue`` also has\nsupport for tracking items that have been added to the queue before,\neliminating the loop problem by simply ignoring duplicates.\n\nBasic Usage\n===========\n\nThe basic usage of a ``WorkQueue`` is very simple--one simply\ninitializes it with a sequence of work items, then iterates over the\nitems, adding new items as necessary::\n\n wq = workq.WorkQueue([item])\n for item in wq:\n # Do work\n\n # Add one item to the queue\n wq.add(new_item)\n\n # Alternatively, add a sequence of items to the queue\n wq.extend(new_items)\n\nEach item added to the queue is tracked, and attempts to add an item\nthat has already been added will simply be ignored. This can be\ndisabled by passing ``unique=False`` to the ``WorkQueue`` constructor.\nIf the work items are not hashable, or must be kept unique based on\nsome property of the item (e.g., an instance attribute), then pass a\n``key`` callable to the ``WorkQueue`` constructor; this callable will\nbe called with one argument--the work item--and must return the key\ncorresponding to that item.\n\nWork Counts\n===========\n\nThe length of a ``WorkQueue`` object is the number of work items still\nin the queue. A ``WorkQueue`` also keeps track of the total number of\nwork items that have been added to it; this count can be accessed\nthrough the ``count`` property. Finally, the number of items that\nhave been worked can be accessed through the ``worked`` property. As\nan example::\n\n >>> wq = workq.WorkQueue(['a', 'b'])\n >>> next(wq)\n 'a'\n >>> wq.add('c')\n >>> len(wq)\n 2\n >>> wq.count\n 3\n >>> wq.worked\n 1\n\nWork Item Uniqueness\n====================\n\nA ``WorkQueue`` object uses a Python ``set`` to track the items that\nhave previously been added, to prevent duplications. This isn't\nrequired for every application, and some applications may have a large\nnumber of work items, or even a never-ending stream of them. To\naccommodate this, the ``unique`` keyword argument may be passed to the\n``WorkQueue`` constructor with a value of ``False``; this will disable\nusing the ``set`` and keep memory usage under control.\n\nAnother problem with using ``set`` is that some work items may not be\nhashable, or the objects may be distinct when the work that they\nrepresent is not. To accommodate this, use the ``key`` keyword\nargument to the ``WorkQueue`` constructor; this identifies a callable,\nsimilar to the ``key`` parameters of ``sort()`` and ``sorted()``,\nwhich is passed the work item and returns a key to use with the\n``set``. This can also be used to keep memory usage under control, by\nallowing the ``set`` to store, say, a short string, rather than a\nlarge object.", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/klmitch/workq", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "workq", "package_url": "https://pypi.org/project/workq/", "platform": "", "project_url": "https://pypi.org/project/workq/", "project_urls": { "Homepage": "https://github.com/klmitch/workq" }, "release_url": "https://pypi.org/project/workq/1.0.1/", "requires_dist": null, "requires_python": "", "summary": "Iterative Work Queue", "version": "1.0.1" }, "last_serial": 5196972, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "3b340c3ead5de67a70a4f44ab37d32d8", "sha256": "454e851df4762cbef57779aefa11774e04cc545f1f5469e3cc1ee9aab1cd86ad" }, "downloads": -1, "filename": "workq-1.0.0.tar.gz", "has_sig": false, "md5_digest": "3b340c3ead5de67a70a4f44ab37d32d8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9690, "upload_time": "2014-09-06T15:40:24", "url": "https://files.pythonhosted.org/packages/ce/46/c1741c35b24f4918133a6d7dd2abab0669e79d5a8f87d4b9294a091b6527/workq-1.0.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "4ae7b56e7dd052124a95877b2ca94031", "sha256": "9fad8e47644cdc4bfddca65fa2271bb7cc39234b733d48c8051442bc2299eda3" }, "downloads": -1, "filename": "workq-1.0.1.tar.gz", "has_sig": false, "md5_digest": "4ae7b56e7dd052124a95877b2ca94031", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9645, "upload_time": "2019-04-27T15:22:24", "url": "https://files.pythonhosted.org/packages/8f/e1/127be6bcf350a917bbe1ec3e2c017197b308843b3f6569fbfa98d77f3f42/workq-1.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "4ae7b56e7dd052124a95877b2ca94031", "sha256": "9fad8e47644cdc4bfddca65fa2271bb7cc39234b733d48c8051442bc2299eda3" }, "downloads": -1, "filename": "workq-1.0.1.tar.gz", "has_sig": false, "md5_digest": "4ae7b56e7dd052124a95877b2ca94031", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9645, "upload_time": "2019-04-27T15:22:24", "url": "https://files.pythonhosted.org/packages/8f/e1/127be6bcf350a917bbe1ec3e2c017197b308843b3f6569fbfa98d77f3f42/workq-1.0.1.tar.gz" } ] }