Skip to content

Commit f061046

Browse files
feat: NestedAsyncIO contextmanager (#872)
* feat: NestedAsyncIO contextmanager This comes from erdewit/nest_asyncio#88 implemented by @CharlieJiangXXX before NestedAsyncIO was archived. It should help with some issues where the patched eventloop causes problems with some other libraries, like Discord.py, that do some "odd" things with eventloops * fix: remove nest-asyncio from requirements * fix: adjust ci coverage and 3.12 support * fix: more loop fixes for 3.12
1 parent 89e1421 commit f061046

File tree

5 files changed

+418
-40
lines changed

5 files changed

+418
-40
lines changed

poetry.lock

+7-33
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pydantic_aioredis/model.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010
from typing import Tuple
1111
from typing import Union
1212

13-
import nest_asyncio
1413
from pydantic_aioredis.abstract import _AbstractModel
15-
from pydantic_aioredis.utils import bytes_to_string
14+
from pydantic_aioredis.utils import bytes_to_string, NestedAsyncIO
1615

1716

1817
class Model(_AbstractModel):
@@ -69,8 +68,8 @@ def __save_from_sync(self):
6968
# Use nest_asyncio so we can call the async save
7069
except RuntimeError:
7170
io_loop = asyncio.new_event_loop()
72-
nest_asyncio.apply()
73-
io_loop.run_until_complete(self.save())
71+
with NestedAsyncIO():
72+
io_loop.run_until_complete(self.save())
7473

7574
@asynccontextmanager
7675
async def update(self):

0 commit comments

Comments
 (0)