All Projects → erdewit → Nest_asyncio

erdewit / Nest_asyncio

Licence: bsd-2-clause
Patch asyncio to allow nested event loops

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Nest asyncio

Uvloop
Ultra fast asyncio event loop.
Stars: ✭ 8,246 (+3548.67%)
Mutual labels:  asyncio, event-loop
Arsenic
Async WebDriver implementation for asyncio and asyncio-compatible frameworks
Stars: ✭ 209 (-7.52%)
Mutual labels:  asyncio
Paco
Small utility library for coroutine-driven asynchronous generic programming in Python 3.4+
Stars: ✭ 198 (-12.39%)
Mutual labels:  asyncio
Fastapi Gino Arq Uvicorn
High-performance Async REST API, in Python. FastAPI + GINO + Arq + Uvicorn (w/ Redis and PostgreSQL).
Stars: ✭ 204 (-9.73%)
Mutual labels:  asyncio
Mojo
✨ Mojolicious - Perl real-time web framework
Stars: ✭ 2,298 (+916.81%)
Mutual labels:  event-loop
Aioodbc
aioodbc - is a library for accessing a ODBC databases from the asyncio
Stars: ✭ 206 (-8.85%)
Mutual labels:  asyncio
Gmqtt
Python MQTT v5.0 async client
Stars: ✭ 195 (-13.72%)
Mutual labels:  asyncio
Piccolo
A fast, user friendly ORM and query builder which supports asyncio.
Stars: ✭ 219 (-3.1%)
Mutual labels:  asyncio
Python Mocket
a socket mock framework - for all kinds of socket animals, web-clients included
Stars: ✭ 209 (-7.52%)
Mutual labels:  asyncio
Aiortc
WebRTC and ORTC implementation for Python using asyncio
Stars: ✭ 2,706 (+1097.35%)
Mutual labels:  asyncio
Aiohttp Devtools
dev tools for aiohttp
Stars: ✭ 202 (-10.62%)
Mutual labels:  asyncio
Python Socketio
Python Socket.IO server and client
Stars: ✭ 2,655 (+1074.78%)
Mutual labels:  asyncio
Aiohttp admin
admin interface for aiohttp application http://aiohttp-admin.readthedocs.io
Stars: ✭ 207 (-8.41%)
Mutual labels:  asyncio
Asphalt
Asphalt application framework (core)
Stars: ✭ 198 (-12.39%)
Mutual labels:  asyncio
Aiofile
Real asynchronous file operations with asyncio support.
Stars: ✭ 214 (-5.31%)
Mutual labels:  asyncio
Aiosmtpd
A reimplementation of the Python stdlib smtpd.py based on asyncio.
Stars: ✭ 195 (-13.72%)
Mutual labels:  asyncio
Aiomisc
aiomisc - miscellaneous utils for asyncio
Stars: ✭ 200 (-11.5%)
Mutual labels:  asyncio
Mode
Python AsyncIO Services
Stars: ✭ 204 (-9.73%)
Mutual labels:  asyncio
Blocked At
Detects node eventloop block and reports where it started
Stars: ✭ 219 (-3.1%)
Mutual labels:  event-loop
Aioreactive
Async/await reactive tools for Python 3.9+
Stars: ✭ 215 (-4.87%)
Mutual labels:  asyncio

|Build| |Status| |PyPiVersion| |License| |Downloads|

Introduction

By design asyncio does not allow <https://bugs.python.org/issue22239>_ 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/workflows/Test/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://pepy.tech/badge/nest-asyncio/month :alt: Number of downloads :target: https://pepy.tech/project/nest-asyncio

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].