Skip to content

Commit 6328931

Browse files
committed
merge
1 parent 10c39cf commit 6328931

File tree

3 files changed

+7
-20
lines changed

3 files changed

+7
-20
lines changed

disnake/gateway.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ def __init__(
165165
*args: Any,
166166
ws: HeartbeatWebSocket,
167167
interval: float,
168+
# this loop sharing is necessary because KeepAliveHandler calls HeartbeatWebSocket's
169+
# async methods and you can't run tasks made using one loop in another
170+
# ("task attached to a different loop"), so the KeepAliveHandler's thread has to
171+
# have access to main (this) thread's asyncio loop, and the only way for it to
172+
# access said loop is to directly pass it as an object
168173
loop: asyncio.AbstractEventLoop,
169174
shard_id: int | None = None,
170175
**kwargs: Any,
@@ -587,7 +592,7 @@ async def received_message(self, raw_msg: str | bytes, /) -> None:
587592
ws=self,
588593
interval=interval,
589594
shard_id=self.shard_id,
590-
loop=asyncio.get_running_loop(), # share loop to the thread
595+
loop=asyncio.get_running_loop(),
591596
)
592597
self._keep_alive.name = "disnake heartbeat thread"
593598
# send a heartbeat immediately

disnake/player.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,7 @@ def __init__(
704704
self,
705705
source: AudioSource,
706706
client: VoiceClient,
707+
# see KeepAliveHandler's reasoning for sharing the loop
707708
loop: asyncio.AbstractEventLoop,
708709
*,
709710
after=None,

disnake/utils.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,29 +56,10 @@
5656
from .enums import Locale
5757

5858
if sys.version_info >= (3, 14):
59-
import threading
6059
from inspect import iscoroutinefunction as iscoroutinefunction
61-
62-
def get_event_loop():
63-
try:
64-
# If there is no event loop, this will raise a RuntimeError starting with Python 3.14+.
65-
# In that case, we create and set a new loop below.
66-
# This is more of a bandaid fix, we should really use asyncio.run in the long term.
67-
return asyncio.get_event_loop()
68-
except RuntimeError:
69-
if threading.current_thread() is not threading.main_thread():
70-
raise
71-
asyncio.set_event_loop(loop := asyncio.new_event_loop())
72-
return loop
7360
else:
7461
from asyncio import iscoroutinefunction as iscoroutinefunction
7562

76-
def get_event_loop():
77-
with warnings.catch_warnings():
78-
warnings.simplefilter("ignore", DeprecationWarning)
79-
# get_event_loop emits deprecation warnings in 3.10-3.13
80-
return asyncio.get_event_loop()
81-
8263

8364
try:
8465
import orjson

0 commit comments

Comments
 (0)