Skip to content

Commit 3aa08f7

Browse files
committed
refactor: nest-asyncio2 and Markdown
1 parent 430091a commit 3aa08f7

File tree

8 files changed

+60
-80
lines changed

8 files changed

+60
-80
lines changed

.github/FUNDING.yml

Lines changed: 0 additions & 2 deletions
This file was deleted.

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# nest-asyncio2
2+
[![Build](https://github.com/Chaoses-Ib/nest-asyncio2/actions/workflows/test.yml/badge.svg?branche=master)](https://github.com/Chaoses-Ib/nest-asyncio2/actions)
3+
[![status](https://img.shields.io/badge/status-stable-green.svg)]()
4+
[![PyPi](https://img.shields.io/pypi/v/nest-asyncio2.svg)](https://pypi.python.org/pypi/nest-asyncio2)
5+
[![License](https://img.shields.io/badge/license-BSD-blue.svg)](LICENSE)
6+
[![Downloads](https://static.pepy.tech/badge/nest-asyncio2/month)](https://pepy.tech/project/nest-asyncio2)
7+
8+
## Introduction
9+
10+
By design asyncio [does not allow](https://github.com/python/cpython/issues/66435)
11+
its event loop to be nested. This presents a practical problem:
12+
When in an environment where the event loop is
13+
already running it's impossible to run tasks and wait
14+
for the result. Trying to do so will give the error
15+
"`RuntimeError: This event loop is already running`".
16+
17+
The issue pops up in various environments, such as web servers,
18+
GUI applications and in Jupyter notebooks.
19+
20+
This module patches asyncio to allow nested use of `asyncio.run` and
21+
`loop.run_until_complete`.
22+
23+
## Installation
24+
25+
```sh
26+
pip3 install nest-asyncio2
27+
```
28+
29+
Python 3.5 or higher is required.
30+
31+
## Usage
32+
33+
```python
34+
import nest_asyncio2
35+
nest_asyncio2.apply()
36+
```
37+
38+
Optionally the specific loop that needs patching can be given
39+
as argument to `apply`, otherwise the current event loop is used.
40+
An event loop can be patched whether it is already running
41+
or not. Only event loops from asyncio can be patched;
42+
Loops from other projects, such as uvloop or quamash,
43+
generally can't be patched.

README.rst

Lines changed: 0 additions & 61 deletions
This file was deleted.
File renamed without changes.

setup.cfg

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
[metadata]
2-
name = nest_asyncio
2+
name = nest-asyncio2
33
version = 1.6.0
44
author = Ewald R. de Wit
55
author_email = [email protected]
66
license = BSD
77
license_files = LICENSE
88
description = Patch asyncio to allow nested event loops
99
keywords = asyncio, nested, eventloop
10-
url = https://github.com/erdewit/nest_asyncio
11-
long_description = file: README.rst
12-
long_description_content_type = text/x-rst
10+
url = https://github.com/Chaoses-Ib/nest-asyncio2
11+
long_description = file: README.md
12+
long_description_content_type = text/markdown
1313
classifiers =
1414
Development Status :: 5 - Production/Stable
1515
Intended Audience :: Developers
@@ -26,7 +26,7 @@ classifiers =
2626
Framework :: AsyncIO
2727

2828
[options]
29-
py_modules = nest_asyncio
29+
py_modules = nest_asyncio2
3030
python_requires = >=3.5
3131

3232
[flake8]

tests/314_task.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# /// script
22
# requires-python = ">=3.14"
33
# dependencies = [
4-
# "nest-asyncio",
4+
# "nest-asyncio2",
55
# ]
66
#
77
# [tool.uv.sources]
8-
# nest-asyncio = { path = "../", editable = true }
8+
# nest-asyncio2 = { path = "../", editable = true }
99
# ///
1010
import asyncio
11-
import nest_asyncio
11+
import nest_asyncio2
1212

13-
nest_asyncio.apply()
13+
nest_asyncio2.apply()
1414

1515
async def f():
1616
print(asyncio.get_running_loop())

tests/314_task_mix.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# /// script
22
# requires-python = ">=3.14"
33
# dependencies = [
4-
# "nest-asyncio",
4+
# "nest-asyncio2",
55
# ]
66
#
77
# [tool.uv.sources]
8-
# nest-asyncio = { path = "../", editable = true }
8+
# nest-asyncio2 = { path = "../", editable = true }
99
# ///
1010
import asyncio
11-
import nest_asyncio
11+
import nest_asyncio2
1212

1313
async def f():
14-
nest_asyncio.apply()
14+
nest_asyncio2.apply()
1515

1616
print(asyncio.get_running_loop())
1717
assert asyncio.get_running_loop() is not None

tests/nest_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# /// script
22
# requires-python = ">=3.5"
33
# dependencies = [
4-
# "nest-asyncio",
4+
# "nest-asyncio2",
55
# ]
66
#
77
# [tool.uv.sources]
8-
# nest-asyncio = { path = "../", editable = true }
8+
# nest-asyncio2 = { path = "../", editable = true }
99
# ///
1010
import asyncio
1111
import sys
1212
import unittest
1313

14-
import nest_asyncio
14+
import nest_asyncio2
1515

1616

1717
def exception_handler(loop, context):
@@ -21,7 +21,7 @@ def exception_handler(loop, context):
2121
class NestTest(unittest.TestCase):
2222
def setUp(self):
2323
self.loop = asyncio.new_event_loop()
24-
nest_asyncio.apply(self.loop)
24+
nest_asyncio2.apply(self.loop)
2525
asyncio.set_event_loop(self.loop)
2626
self.loop.set_debug(True)
2727
self.loop.set_exception_handler(exception_handler)

0 commit comments

Comments
 (0)