{ "info": { "author": "Ian McCracken", "author_email": "ian.mccracken@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "Greenlight\n==========\n``greenlight`` is a powerful decorator that helps you write code using gevent_.\nYou can decorate an existing function to run it in a greenlet::\n\n >>> from greenlight import greenlight\n >>> from gevent.greenlet import Greenlet\n >>> @greenlight\n ... def async_squaring(n):\n ... \"An extremely useful function\"\n ... return n**2\n ...\n >>> g = async_squaring(10)\n >>> isinstance(g, Greenlet)\n True\n >>> g.get()\n 100\n\nMore interestingly, you can chain greenlets inside a greenlit generator\n(similar to Twisted's inlineCallbacks_). This saves boilerplate; one would\notherwise have to call ``gevent.spawn()`` on each function, then either\n``link()`` them together, or, perhaps, call ``join()`` or ``get()`` on each one\nand pass the result to the next. With ``greenlight``, you can simply yield to\nget results inline::\n\n >>> @greenlight\n ... def square_thrice(n):\n ... squared = yield async_squaring(n)\n ... tothe4th = yield async_squaring(squared)\n ... tothe8th = yield async_squaring(tothe4th)\n ...\n >>> square_thrice(2).get()\n 256\n\nSince a greenlit function always returns a greenlet itself, you can write code\nvery similar to the synchronous code you normally would, while still ensuring\nexecution order, simply by chaining greenlit functions together. \n\nYou can explicitly return values from the greenlit generator using the\n``green_return`` function. If ``green_return`` is not used, the result of the\nlast greenlet yielded is returned (as in the previous example)::\n\n >>> from greenlight import green_return\n >>> @greenlight\n ... def greater_than_100():\n ... a = 2\n ... while True:\n ... a = yield async_squaring(a)\n ... if a>100:\n ... green_return(a)\n ...\n >>> greater_than_100().get()\n 256\n\nError handling works as you would expect::\n\n >>> @greenlight\n ... def something_bad():\n ... raise Exception('O NOES')\n ...\n >>> @greenlight\n ... def main():\n ... try:\n ... hundred = yield async_squaring(10)\n ... yield something_bad()\n ... except Exception, e:\n ... print e\n ... green_return(None)\n ...\n >>> main().get()\n O NOES\n\n``greenlight`` normally behaves like gevent.spawn_, in that it starts greenlets for\nyou. If you don't want that to happen, you can use ``greenlight_nostart``::\n\n >>> from greenlight import greenlight_nostart as greenlight\n >>> @greenlight\n ... def squared(n):\n ... return n**2\n ...\n >>> g = squared(4)\n >>> g.started\n False\n >>> g.start(); g.get()\n 16\n\n.. _inlineCallbacks: http://twistedmatrix.com/documents/8.1.0/api/twisted.internet.defer.html#inlineCallbacks\n.. _gevent: http://www.gevent.org/\n.. _gevent.spawn: http://www.gevent.org/gevent.html#spawn-helpers", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://concisionandconcinnity.blogspot.com", "keywords": "gevent", "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "greenlight", "package_url": "https://pypi.org/project/greenlight/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/greenlight/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://concisionandconcinnity.blogspot.com" }, "release_url": "https://pypi.org/project/greenlight/0.1/", "requires_dist": null, "requires_python": null, "summary": "Helps you write code using gevent", "version": "0.1" }, "last_serial": 744267, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "637190c78b5f8db951005c69d9c28ccf", "sha256": "ca98f75668ac7c0b822eecf6139ac805931f891a53add904a9081081c9cf4ea7" }, "downloads": -1, "filename": "greenlight-0.1-py2.6.egg", "has_sig": false, "md5_digest": "637190c78b5f8db951005c69d9c28ccf", "packagetype": "bdist_egg", "python_version": "2.6", "requires_python": null, "size": 6954, "upload_time": "2010-10-17T21:00:12", "url": "https://files.pythonhosted.org/packages/95/1f/40c67b1546bc92ac536dab5e3ed45c4fb90e8b0da939e2840bdad30419cb/greenlight-0.1-py2.6.egg" }, { "comment_text": "", "digests": { "md5": "e0e419123fe32ee6b008f7bb5d2b4301", "sha256": "2586686fd38d444ab3d27d850506da6a65347d6a2678b43464f7aad97c90bae1" }, "downloads": -1, "filename": "greenlight-0.1-py2.7.egg", "has_sig": false, "md5_digest": "e0e419123fe32ee6b008f7bb5d2b4301", "packagetype": "bdist_egg", "python_version": "2.7", "requires_python": null, "size": 6936, "upload_time": "2010-10-17T20:58:39", "url": "https://files.pythonhosted.org/packages/f7/cf/f3845388b0e6932d3549844d4de8afa1de2e1fea82ae239a40bff0eb6a00/greenlight-0.1-py2.7.egg" }, { "comment_text": "", "digests": { "md5": "e0c019b208d0d8a4061adda2adb59840", "sha256": "515ca5ef2ed221307ecc7081774a1efe3874649e2b3768d284323880060ee7ba" }, "downloads": -1, "filename": "greenlight-0.1.tar.gz", "has_sig": false, "md5_digest": "e0c019b208d0d8a4061adda2adb59840", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3293, "upload_time": "2010-10-17T20:58:38", "url": "https://files.pythonhosted.org/packages/84/74/bd83a731ea7e4574e1ce2aa343026771e4779219970bb1efa9b4111349f8/greenlight-0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "637190c78b5f8db951005c69d9c28ccf", "sha256": "ca98f75668ac7c0b822eecf6139ac805931f891a53add904a9081081c9cf4ea7" }, "downloads": -1, "filename": "greenlight-0.1-py2.6.egg", "has_sig": false, "md5_digest": "637190c78b5f8db951005c69d9c28ccf", "packagetype": "bdist_egg", "python_version": "2.6", "requires_python": null, "size": 6954, "upload_time": "2010-10-17T21:00:12", "url": "https://files.pythonhosted.org/packages/95/1f/40c67b1546bc92ac536dab5e3ed45c4fb90e8b0da939e2840bdad30419cb/greenlight-0.1-py2.6.egg" }, { "comment_text": "", "digests": { "md5": "e0e419123fe32ee6b008f7bb5d2b4301", "sha256": "2586686fd38d444ab3d27d850506da6a65347d6a2678b43464f7aad97c90bae1" }, "downloads": -1, "filename": "greenlight-0.1-py2.7.egg", "has_sig": false, "md5_digest": "e0e419123fe32ee6b008f7bb5d2b4301", "packagetype": "bdist_egg", "python_version": "2.7", "requires_python": null, "size": 6936, "upload_time": "2010-10-17T20:58:39", "url": "https://files.pythonhosted.org/packages/f7/cf/f3845388b0e6932d3549844d4de8afa1de2e1fea82ae239a40bff0eb6a00/greenlight-0.1-py2.7.egg" }, { "comment_text": "", "digests": { "md5": "e0c019b208d0d8a4061adda2adb59840", "sha256": "515ca5ef2ed221307ecc7081774a1efe3874649e2b3768d284323880060ee7ba" }, "downloads": -1, "filename": "greenlight-0.1.tar.gz", "has_sig": false, "md5_digest": "e0c019b208d0d8a4061adda2adb59840", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3293, "upload_time": "2010-10-17T20:58:38", "url": "https://files.pythonhosted.org/packages/84/74/bd83a731ea7e4574e1ce2aa343026771e4779219970bb1efa9b4111349f8/greenlight-0.1.tar.gz" } ] }