Skip to main content

Patch asyncio to allow nested event loops

Project description

Introduction

By design asyncio does not allow 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

pip3 install git+https://github.com/ufoptg/asyncNestADV.git

Python 3.5 or higher is required.

Usage

import nest_asyncio
nest_asyncio.apply()
nest_asyncio.revert()

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nest_asyncio_adv-1.7.0b0.tar.gz (19.6 kB view details)

Uploaded Source

Built Distribution

nest_asyncio_adv-1.7.0b0-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

Details for the file nest_asyncio_adv-1.7.0b0.tar.gz.

File metadata

  • Download URL: nest_asyncio_adv-1.7.0b0.tar.gz
  • Upload date:
  • Size: 19.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.19

File hashes

Hashes for nest_asyncio_adv-1.7.0b0.tar.gz
Algorithm Hash digest
SHA256 2580c8021371c311adba6bac0f10ceda4834af2c22a71bcd65ec2d3d1609a678
MD5 069a2edd033de96446691e80fe48e346
BLAKE2b-256 29282ad79a336dc8431ff06a38b4e24c3aadb1f983c23d50bbfd3254aaf5af6e

See more details on using hashes here.

File details

Details for the file nest_asyncio_adv-1.7.0b0-py3-none-any.whl.

File metadata

File hashes

Hashes for nest_asyncio_adv-1.7.0b0-py3-none-any.whl
Algorithm Hash digest
SHA256 f5f75f16fb8c5f53fc0297cb95f5c30602f673c033e25f36a7a973e383abfb03
MD5 abcf4de938b170fa2a2069986cf010f3
BLAKE2b-256 84e0326b2d265141e1ae388ee51b59de4082848c8fa5263d7ce28340b97b9b95

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page