Skip to content

Commit 1af7c33

Browse files
fix: support asyncio loops on py314
1 parent d6bc109 commit 1af7c33

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

disnake/client.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import sys
99
import traceback
1010
import types
11-
import warnings
1211
from datetime import datetime, timedelta
1312
from errno import ECONNRESET
1413
from typing import (
@@ -407,9 +406,7 @@ def __init__(
407406
self.ws: DiscordWebSocket = None # type: ignore
408407

409408
if loop is None:
410-
with warnings.catch_warnings():
411-
warnings.simplefilter("ignore", DeprecationWarning)
412-
self.loop: asyncio.AbstractEventLoop = asyncio.get_event_loop()
409+
self.loop: asyncio.AbstractEventLoop = utils.get_event_loop()
413410
else:
414411
self.loop: asyncio.AbstractEventLoop = loop
415412

disnake/ext/tasks/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import inspect
88
import sys
99
import traceback
10-
import warnings
1110
from collections.abc import Sequence
1211
from typing import (
1312
TYPE_CHECKING,
@@ -325,9 +324,7 @@ def start(self, *args: Any, **kwargs: Any) -> asyncio.Task[None]:
325324
args = (self._injected, *args)
326325

327326
if self.loop is MISSING:
328-
with warnings.catch_warnings():
329-
warnings.simplefilter("ignore", DeprecationWarning)
330-
self.loop = asyncio.get_event_loop()
327+
self.loop = disnake.utils.get_event_loop()
331328

332329
self._task = self.loop.create_task(self._loop(*args, **kwargs))
333330
return self._task

disnake/utils.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,19 @@
5252

5353
if sys.version_info >= (3, 11):
5454
from inspect import iscoroutine as iscoroutine, iscoroutinefunction as iscoroutinefunction
55+
56+
def get_event_loop():
57+
try:
58+
return asyncio.get_running_loop()
59+
except RuntimeError:
60+
return asyncio.new_event_loop()
5561
else:
56-
from asyncio import iscoroutine as iscoroutine, iscoroutinefunction as iscoroutinefunction
62+
from asyncio import (
63+
get_event_loop as get_event_loop,
64+
iscoroutine as iscoroutine,
65+
iscoroutinefunction as iscoroutinefunction,
66+
)
67+
5768

5869
try:
5970
import orjson

0 commit comments

Comments
 (0)