Skip to content

Commit

Permalink
feat: NestedAsyncIO contextmanager (#872)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
andrewthetechie authored May 8, 2024
1 parent 89e1421 commit f061046
Show file tree
Hide file tree
Showing 5 changed files with 418 additions and 40 deletions.
40 changes: 7 additions & 33 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions pydantic_aioredis/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
from typing import Tuple
from typing import Union

import nest_asyncio
from pydantic_aioredis.abstract import _AbstractModel
from pydantic_aioredis.utils import bytes_to_string
from pydantic_aioredis.utils import bytes_to_string, NestedAsyncIO


class Model(_AbstractModel):
Expand Down Expand Up @@ -69,8 +68,8 @@ def __save_from_sync(self):
# Use nest_asyncio so we can call the async save
except RuntimeError:
io_loop = asyncio.new_event_loop()
nest_asyncio.apply()
io_loop.run_until_complete(self.save())
with NestedAsyncIO():
io_loop.run_until_complete(self.save())

@asynccontextmanager
async def update(self):
Expand Down
Loading

0 comments on commit f061046

Please sign in to comment.