|Build| |Status| |PyPiVersion| |License| |Downloads|
Introduction
------------
By design asyncio `does not allow <https://github.com/python/cpython/issues/66435>`_
its event loop to be nested. This presents a practical problem:
When in an environment where the event loop is
already running it's impossible to run tasks and wait
for the result. Trying to do so will give the error
"``RuntimeError: This event loop is already running``".
The issue pops up in various environments, such as web servers,
GUI applications and in Jupyter notebooks.
This module patches asyncio to allow nested use of ``asyncio.run`` and
``loop.run_until_complete``.
Installation
------------
.. code-block::
pip3 install nest_asyncio
Python 3.5 or higher is required.
Usage
-----
.. code-block:: python
import nest_asyncio
nest_asyncio.apply()
Optionally the specific loop that needs patching can be given
as argument to ``apply``, otherwise the current event loop is used.
An event loop can be patched whether it is already running
or not. Only event loops from asyncio can be patched;
Loops from other projects, such as uvloop or quamash,
generally can't be patched.
.. |Build| image:: https://github.com/erdewit/nest_asyncio/actions/workflows/test.yml/badge.svg?branche=master
:alt: Build
:target: https://github.com/erdewit/nest_asyncio/actions
.. |PyPiVersion| image:: https://img.shields.io/pypi/v/nest_asyncio.svg
:alt: PyPi
:target: https://pypi.python.org/pypi/nest_asyncio
.. |Status| image:: https://img.shields.io/badge/status-stable-green.svg
:alt:
.. |License| image:: https://img.shields.io/badge/license-BSD-blue.svg
:alt:
.. |Downloads| image:: https://static.pepy.tech/badge/nest-asyncio/month
:alt: Number of downloads
:target: https://pepy.tech/project/nest-asyncio
Raw data
{
"_id": null,
"home_page": "https://github.com/erdewit/nest_asyncio",
"name": "nest-asyncio",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.5",
"maintainer_email": "",
"keywords": "asyncio,nested,eventloop",
"author": "Ewald R. de Wit",
"author_email": "ewald.de.wit@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/83/f8/51569ac65d696c8ecbee95938f89d4abf00f47d58d48f6fbabfe8f0baefe/nest_asyncio-1.6.0.tar.gz",
"platform": null,
"description": "|Build| |Status| |PyPiVersion| |License| |Downloads|\n\nIntroduction\n------------\n\nBy design asyncio `does not allow <https://github.com/python/cpython/issues/66435>`_\nits event loop to be nested. This presents a practical problem:\nWhen in an environment where the event loop is\nalready running it's impossible to run tasks and wait\nfor the result. Trying to do so will give the error\n\"``RuntimeError: This event loop is already running``\".\n\nThe issue pops up in various environments, such as web servers,\nGUI applications and in Jupyter notebooks.\n\nThis module patches asyncio to allow nested use of ``asyncio.run`` and\n``loop.run_until_complete``.\n\nInstallation\n------------\n\n.. code-block::\n\n pip3 install nest_asyncio\n\nPython 3.5 or higher is required.\n\nUsage\n-----\n\n.. code-block:: python\n\n import nest_asyncio\n nest_asyncio.apply()\n\nOptionally the specific loop that needs patching can be given\nas argument to ``apply``, otherwise the current event loop is used.\nAn event loop can be patched whether it is already running\nor not. Only event loops from asyncio can be patched;\nLoops from other projects, such as uvloop or quamash,\ngenerally can't be patched.\n\n\n.. |Build| image:: https://github.com/erdewit/nest_asyncio/actions/workflows/test.yml/badge.svg?branche=master\n :alt: Build\n :target: https://github.com/erdewit/nest_asyncio/actions\n\n.. |PyPiVersion| image:: https://img.shields.io/pypi/v/nest_asyncio.svg\n :alt: PyPi\n :target: https://pypi.python.org/pypi/nest_asyncio\n\n.. |Status| image:: https://img.shields.io/badge/status-stable-green.svg\n :alt:\n\n.. |License| image:: https://img.shields.io/badge/license-BSD-blue.svg\n :alt:\n\n.. |Downloads| image:: https://static.pepy.tech/badge/nest-asyncio/month\n :alt: Number of downloads\n :target: https://pepy.tech/project/nest-asyncio\n\n",
"bugtrack_url": null,
"license": "BSD",
"summary": "Patch asyncio to allow nested event loops",
"version": "1.6.0",
"project_urls": {
"Homepage": "https://github.com/erdewit/nest_asyncio"
},
"split_keywords": [
"asyncio",
"nested",
"eventloop"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "a0c4c2971a3ba4c6103a3d10c4b0f24f461ddc027f0f09763220cf35ca1401b3",
"md5": "dbe512b8ff01d1e68e61dfa0f91f37e5",
"sha256": "87af6efd6b5e897c81050477ef65c62e2b2f35d51703cae01aff2905b1852e1c"
},
"downloads": -1,
"filename": "nest_asyncio-1.6.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "dbe512b8ff01d1e68e61dfa0f91f37e5",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.5",
"size": 5195,
"upload_time": "2024-01-21T14:25:17",
"upload_time_iso_8601": "2024-01-21T14:25:17.223200Z",
"url": "https://files.pythonhosted.org/packages/a0/c4/c2971a3ba4c6103a3d10c4b0f24f461ddc027f0f09763220cf35ca1401b3/nest_asyncio-1.6.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "83f851569ac65d696c8ecbee95938f89d4abf00f47d58d48f6fbabfe8f0baefe",
"md5": "4a15c56d692367a24ea12072e2e475f3",
"sha256": "6f172d5449aca15afd6c646851f4e31e02c598d553a667e38cafa997cfec55fe"
},
"downloads": -1,
"filename": "nest_asyncio-1.6.0.tar.gz",
"has_sig": false,
"md5_digest": "4a15c56d692367a24ea12072e2e475f3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.5",
"size": 7418,
"upload_time": "2024-01-21T14:25:19",
"upload_time_iso_8601": "2024-01-21T14:25:19.227547Z",
"url": "https://files.pythonhosted.org/packages/83/f8/51569ac65d696c8ecbee95938f89d4abf00f47d58d48f6fbabfe8f0baefe/nest_asyncio-1.6.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-01-21 14:25:19",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "erdewit",
"github_project": "nest_asyncio",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "nest-asyncio"
}