{ "info": { "author": "Dmitry Malinovsky", "author_email": "damalinov@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "aionursery\n==========\n\n.. image:: https://travis-ci.com/malinoff/aionursery.svg?branch=master\n :target: https://travis-ci.com/malinoff/aionursery\n\n.. image:: https://codecov.io/gh/malinoff/aionursery/branch/master/graph/badge.svg\n :target: https://codecov.io/gh/malinoff/aionursery\n\n\nThis library implements a Nursery object, similar to trio's Nursery_ for ``asyncio``.\n\n.. _Nursery: http://trio.readthedocs.io/en/latest/reference-core.html#nurseries-and-spawning\n\n.. code-block:: python\n\n async def child():\n ...\n\n async def parent():\n async with aionursery.Nursery() as nursery:\n # Make two concurrent calls to child\n nursery.start_soon(child())\n nursery.start_soon(child())\n\n\nTasks form a tree: when you run your main coroutine (via ``asyncio.get_event_loop().run_until_complete`` or ``asyncio.run``), this creates an initial task, and all your other tasks will be children, grandchildren, etc. of the main task.\n\nThe body of the ``async with`` block acts like an initial task that's running inside the nursery, and then each call to ``nursery.start_soon`` adds another task that runs in parallel.\n\nKeep in mind that:\n\n* If any task inside the nursery raises an unhandled exception, then the nursery immediately cancels all the tasks inside the nursery.\n\n* Since all of the tasks are running concurrently inside the async with block, the block does not exit until all tasks have completed. If you\u2019ve used other concurrency frameworks, then you can think of it as, the de-indentation at the end of the async with automatically \u201cjoins\u201d (waits for) all of the tasks in the nursery.\n\n* Once all the tasks have finished, then:\n * The nursery is marked as \u201cclosed\u201d, meaning that no new tasks can be started inside it.\n * Any unhandled exceptions are re-raised inside the parent task. If there are multiple exceptions, then they\u2019re collected up into a single MultiError exception.\n\nSince all tasks are descendents of the initial task, one consequence of this is that the parent can\u2019t finish until all tasks have finished.\n\nPlease note that you can't reuse an already exited nursery. Trying to re-open it again, or to ``start_soon`` more tasks in it will raise ``NurseryClosed``.\n\nShielding some tasks from being cancelled\n-----------------------------------------\n\nSometimes, however, you need to have an opposite behavior: a child must execute no matter what exceptions are raised in other tasks.\nImagine a payment transaction running in one task, and an sms sending in another.\nYou certainly don't want an sms sending error to cancel a payment transaction.\n\nFor that, you can ``asyncio.shield`` your tasks before starting them in the nursery:\n\n.. code-block:: python\n\n async def perform_payment():\n ...\n\n async def send_sms():\n ...\n\n async def parent():\n async with Nursery() as nursery:\n nursery.start_soon(asyncio.shield(perform_payment()))\n nursery.start_soon(send_sms())\n\n\nGetting results from children\n-----------------------------\n\nIf your background tasks are not quite long-lived and return some useful values that you want to process, you can gather all tasks into a list and use ``asyncio.wait`` (or similar functions) as usual:\n\n.. code-block:: python\n\n async def parent():\n async with Nursery() as nursery:\n task_foo = nursery.start_soon(foo())\n task_bar = nursery.start_soon(bar())\n results = await asyncio.wait([task_foo, task_bar])\n\n\nIf your background tasks are long-lived, you should use ``asyncio.Queue`` to pass objects between children and parent tasks:\n\n.. code-block:: python\n\n async def child(queue):\n while True:\n data = await from_external_system()\n await queue.put(data)\n\n async def parent():\n queue = asyncio.Queue()\n async with Nursery() as nursery:\n nursery.start_soon(child(queue))\n while some_condition():\n data = await queue.get()\n await do_stuff_with(data)\n\n\nIntegration with ``async_timeout``\n----------------------------------\n\nYou can wrap a nursery in a ``async_timeout.timeout`` context manager.\nWhen timeout happens, the whole nursery cancels:\n\n.. code-block:: python\n\n from async_timeout import timeout\n\n async def child():\n await asyncio.sleep(1000 * 1000)\n\n async def parent():\n async with timeout(10):\n async with Nursery() as nursery:\n nursery.start_soon(child())\n await asyncio.sleep(1000 * 1000)\n", "description_content_type": "text/x-rst", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/malinoff/aionursery", "keywords": "", "license": "Apache-2.0", "maintainer": "Dmitry Malinovsky", "maintainer_email": "damalinov@gmail.com", "name": "aionursery", "package_url": "https://pypi.org/project/aionursery/", "platform": "", "project_url": "https://pypi.org/project/aionursery/", "project_urls": { "Homepage": "https://github.com/malinoff/aionursery" }, "release_url": "https://pypi.org/project/aionursery/0.3.0/", "requires_dist": null, "requires_python": ">=3.5,<4.0", "summary": "Manage background asyncio tasks", "version": "0.3.0" }, "last_serial": 4231414, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "4154d0bfb569f932ccb36bd394421b49", "sha256": "be5e9e5b05425fd921f7856bce8c990df2b718901fdd74ca0e8ac0c5f014256d" }, "downloads": -1, "filename": "aionursery-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "4154d0bfb569f932ccb36bd394421b49", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.4,<4.0", "size": 15654, "upload_time": "2018-06-11T09:06:18", "url": "https://files.pythonhosted.org/packages/6d/fe/aafef522ffd3de04e72f7c5f90234408925cf63278ec361d9fe707def2eb/aionursery-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "61d1738ad114bf75b7faf6db7f1b23d3", "sha256": "6d1c5f128c48a980b5111d045abebfae051366d6ae2c9f889ef11c65e428457f" }, "downloads": -1, "filename": "aionursery-0.1.0.tar.gz", "has_sig": false, "md5_digest": "61d1738ad114bf75b7faf6db7f1b23d3", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.4,<4.0", "size": 5837, "upload_time": "2018-06-11T09:06:19", "url": "https://files.pythonhosted.org/packages/ea/df/20ded2ec150bf4041894b3196de39aeb6259bebe66c2cb2a59420b953951/aionursery-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "9e41494f3c2e1d388f5d3a907b98bbe6", "sha256": "48814669a4166dc8fd719f52bd9f30d3a14e83df9241a0febc8ecc639a91bbe6" }, "downloads": -1, "filename": "aionursery-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "9e41494f3c2e1d388f5d3a907b98bbe6", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.4,<4.0", "size": 17223, "upload_time": "2018-06-11T09:08:42", "url": "https://files.pythonhosted.org/packages/1e/cb/c578c3d366dc617980342838fbd0e2d6d2ac4a00398e498c65038f31fdd6/aionursery-0.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a74ad7a691452df2c47f39aa728f8d6b", "sha256": "5b5435c0a2a16100405b87bfb907067af594ef1e9b147888fcd21d7e3323b013" }, "downloads": -1, "filename": "aionursery-0.1.1.tar.gz", "has_sig": false, "md5_digest": "a74ad7a691452df2c47f39aa728f8d6b", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.4,<4.0", "size": 7609, "upload_time": "2018-06-11T09:08:43", "url": "https://files.pythonhosted.org/packages/08/61/2bc15b21cb3b311893321d00b8e5879840577360f4f8b491f19b7f397600/aionursery-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "c15c1b01cb8677c2ad658b2d1235c137", "sha256": "63d51c977acb550dd7d4a287089a5799013b0e794f1dfc0ed8f1aa995f9a6ba1" }, "downloads": -1, "filename": "aionursery-0.1.2-py3-none-any.whl", "has_sig": false, "md5_digest": "c15c1b01cb8677c2ad658b2d1235c137", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5,<4.0", "size": 17219, "upload_time": "2018-06-11T09:10:32", "url": "https://files.pythonhosted.org/packages/64/98/a5923d8470257362eae7328ac825f4a96c33e0c10d4f7bdedf19277def78/aionursery-0.1.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "0818f8b946cd8a0dc4b3cc6d395dc758", "sha256": "aedb840d8b9cbbea9693b049bf7b95dc401621420543afc66775471605d60125" }, "downloads": -1, "filename": "aionursery-0.1.2.tar.gz", "has_sig": false, "md5_digest": "0818f8b946cd8a0dc4b3cc6d395dc758", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5,<4.0", "size": 7603, "upload_time": "2018-06-11T09:10:34", "url": "https://files.pythonhosted.org/packages/f6/e1/1c1bb40e5ae92aeb04b572c86e1d3b35c405bcfbfa915bb4acb6d09d38d2/aionursery-0.1.2.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "ae8be9235ae14ee89a23f2200fed6135", "sha256": "e61fd340203665051bc3ff99a9d5270875ed4aecc556d13d232ddd6bc71d969a" }, "downloads": -1, "filename": "aionursery-0.1.3-py3-none-any.whl", "has_sig": false, "md5_digest": "ae8be9235ae14ee89a23f2200fed6135", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5,<4.0", "size": 17211, "upload_time": "2018-06-11T10:34:24", "url": "https://files.pythonhosted.org/packages/ce/8f/49b48659b2c735fedec53990ceca916cbefe5317cfc1773c681b893a4dd6/aionursery-0.1.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "c1968b21dab54bee67fd9ea774d675d8", "sha256": "f2472594d607527c0da09b95dc0a89728dddab827bfa0f7eb9456dbf9b7f6e2d" }, "downloads": -1, "filename": "aionursery-0.1.3.tar.gz", "has_sig": false, "md5_digest": "c1968b21dab54bee67fd9ea774d675d8", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5,<4.0", "size": 7602, "upload_time": "2018-06-11T10:34:25", "url": "https://files.pythonhosted.org/packages/de/17/14064db1f0aa74122c9eb3b47ae1d87e8ca59938ad7e372244c977044198/aionursery-0.1.3.tar.gz" } ], "0.1.4": [ { "comment_text": "", "digests": { "md5": "0f502f42f2dfead6e186b001f8baba42", "sha256": "0c67c7df301e82ea0863d55fccad3cbeb088e8b15b18783034140da62c2851e4" }, "downloads": -1, "filename": "aionursery-0.1.4-py3-none-any.whl", "has_sig": false, "md5_digest": "0f502f42f2dfead6e186b001f8baba42", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5,<4.0", "size": 17221, "upload_time": "2018-06-11T12:30:13", "url": "https://files.pythonhosted.org/packages/27/99/03d1bdec8ff131c7f991a7eb32426794a378512911d9949c6d796a5f7ea3/aionursery-0.1.4-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "af5907364b1eed630f0b8df4e44c4a2c", "sha256": "41d26c591719c0feb01ca5b4dae0c5e8bdbd7847425e262eedd99c15e690ab20" }, "downloads": -1, "filename": "aionursery-0.1.4.tar.gz", "has_sig": false, "md5_digest": "af5907364b1eed630f0b8df4e44c4a2c", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5,<4.0", "size": 7645, "upload_time": "2018-06-11T12:30:32", "url": "https://files.pythonhosted.org/packages/fc/86/04f0d6ea78ad3a501516b1aaa034e326eccbf4147efd6226d7acd6407f26/aionursery-0.1.4.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "27efd0430016b079afac6572a882a4b6", "sha256": "f1c230a926176a9455edb7e1f26285e70b21a846ea2ae69cb7e913f489fb17b8" }, "downloads": -1, "filename": "aionursery-0.2.1-py3-none-any.whl", "has_sig": false, "md5_digest": "27efd0430016b079afac6572a882a4b6", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5,<4.0", "size": 17297, "upload_time": "2018-07-16T16:55:35", "url": "https://files.pythonhosted.org/packages/86/7c/69243afb3c2723a1f430ea5af5373a598a99fdd0296ec1468599e0ff6a1b/aionursery-0.2.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "e174415d760694d217e71b3f9e1e55d5", "sha256": "4991dda9bd32d698e60f2228dd619fc23593064041de17239dd0d26c0ea17291" }, "downloads": -1, "filename": "aionursery-0.2.1.tar.gz", "has_sig": false, "md5_digest": "e174415d760694d217e71b3f9e1e55d5", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5,<4.0", "size": 7749, "upload_time": "2018-07-16T16:55:36", "url": "https://files.pythonhosted.org/packages/00/70/1d7678500ddff42ecfc3570d9b4346f00b4f062450cf9efef2c4131d6b13/aionursery-0.2.1.tar.gz" } ], "0.2.2": [ { "comment_text": "", "digests": { "md5": "e1d2ba7d72dc5c07e581d090b3f127e6", "sha256": "8aa2df58fed355db29f9eb0982b67294d485b262e2241330113824af5a2d1d89" }, "downloads": -1, "filename": "aionursery-0.2.2-py3-none-any.whl", "has_sig": false, "md5_digest": "e1d2ba7d72dc5c07e581d090b3f127e6", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5,<4.0", "size": 17336, "upload_time": "2018-07-17T08:25:39", "url": "https://files.pythonhosted.org/packages/5b/9e/5dba279240550539843ae9cc4d6dec48ba73fd7a573eb81c132b4bbfed82/aionursery-0.2.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "bab404476e5d8c6b13bcac8cde603b26", "sha256": "712fab048777edb081426b513e23d1ff7474b38045ba183664f221bc212b5eee" }, "downloads": -1, "filename": "aionursery-0.2.2.tar.gz", "has_sig": false, "md5_digest": "bab404476e5d8c6b13bcac8cde603b26", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5,<4.0", "size": 7748, "upload_time": "2018-07-17T08:25:41", "url": "https://files.pythonhosted.org/packages/f9/cf/8989329521517ed9024b23dbaaabb53393cc9c18e20ef82e378771e3c2bb/aionursery-0.2.2.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "2913cf87936da01161a14ec828324b64", "sha256": "bc6953501add61dd0e24b1755a645dfbccd904c2737b6fce4e28f3294bab88d0" }, "downloads": -1, "filename": "aionursery-0.3.0-py3-none-any.whl", "has_sig": false, "md5_digest": "2913cf87936da01161a14ec828324b64", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5,<4.0", "size": 17463, "upload_time": "2018-09-02T16:03:43", "url": "https://files.pythonhosted.org/packages/d6/a0/5c26cfc5385c914fed884d834d4b7225195b4a2866fe6fb3edf37a3f2711/aionursery-0.3.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "1bccba5879e1ac138bd9de085cec629b", "sha256": "0836d9863393cfe68a18e91c6a00af788960cb40207a1f19105270012f4e08ce" }, "downloads": -1, "filename": "aionursery-0.3.0.tar.gz", "has_sig": false, "md5_digest": "1bccba5879e1ac138bd9de085cec629b", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5,<4.0", "size": 7772, "upload_time": "2018-09-02T16:03:44", "url": "https://files.pythonhosted.org/packages/6a/0d/6710f10951807fb67b531927afbb8b33a3dd9fbe41db5ae0a940019cd7de/aionursery-0.3.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "2913cf87936da01161a14ec828324b64", "sha256": "bc6953501add61dd0e24b1755a645dfbccd904c2737b6fce4e28f3294bab88d0" }, "downloads": -1, "filename": "aionursery-0.3.0-py3-none-any.whl", "has_sig": false, "md5_digest": "2913cf87936da01161a14ec828324b64", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5,<4.0", "size": 17463, "upload_time": "2018-09-02T16:03:43", "url": "https://files.pythonhosted.org/packages/d6/a0/5c26cfc5385c914fed884d834d4b7225195b4a2866fe6fb3edf37a3f2711/aionursery-0.3.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "1bccba5879e1ac138bd9de085cec629b", "sha256": "0836d9863393cfe68a18e91c6a00af788960cb40207a1f19105270012f4e08ce" }, "downloads": -1, "filename": "aionursery-0.3.0.tar.gz", "has_sig": false, "md5_digest": "1bccba5879e1ac138bd9de085cec629b", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5,<4.0", "size": 7772, "upload_time": "2018-09-02T16:03:44", "url": "https://files.pythonhosted.org/packages/6a/0d/6710f10951807fb67b531927afbb8b33a3dd9fbe41db5ae0a940019cd7de/aionursery-0.3.0.tar.gz" } ] }