Skip to content

Commit cc1254b

Browse files
committed
Don't use get_running_loop outside of coroutines.
get_event_loop() returns the running loop if there's one anyway.
1 parent e444fb5 commit cc1254b

File tree

3 files changed

+3
-15
lines changed

3 files changed

+3
-15
lines changed

src/websockets/legacy/client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
from ..http import USER_AGENT, build_host
3434
from ..typing import ExtensionHeader, LoggerLike, Origin, Subprotocol
3535
from ..uri import WebSocketURI, parse_uri
36-
from .compatibility import asyncio_get_running_loop
3736
from .handshake import build_request, check_response
3837
from .http import read_response
3938
from .protocol import WebSocketCommonProtocol
@@ -517,7 +516,7 @@ def __init__(
517516
# Backwards compatibility: the loop parameter used to be supported.
518517
loop: Optional[asyncio.AbstractEventLoop] = kwargs.pop("loop", None)
519518
if loop is None:
520-
loop = asyncio_get_running_loop()
519+
loop = asyncio.get_event_loop()
521520
else:
522521
warnings.warn("remove loop argument", DeprecationWarning)
523522

src/websockets/legacy/compatibility.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,3 @@ def loop_if_py_lt_38(loop: asyncio.AbstractEventLoop) -> Dict[str, Any]:
99
1010
"""
1111
return {"loop": loop} if sys.version_info[:2] < (3, 8) else {}
12-
13-
14-
def asyncio_get_running_loop() -> asyncio.AbstractEventLoop:
15-
"""
16-
Helper for the deprecation of get_event_loop in Python 3.10.
17-
18-
"""
19-
if sys.version_info[:2] < (3, 10): # pragma: no cover
20-
return asyncio.get_event_loop()
21-
else: # pragma: no cover
22-
return asyncio.get_running_loop()

src/websockets/legacy/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
from ..headers import build_extension, parse_extension, parse_subprotocol
4343
from ..http import USER_AGENT
4444
from ..typing import ExtensionHeader, LoggerLike, Origin, Subprotocol
45-
from .compatibility import asyncio_get_running_loop, loop_if_py_lt_38
45+
from .compatibility import loop_if_py_lt_38
4646
from .handshake import build_response, check_request
4747
from .http import read_request
4848
from .protocol import WebSocketCommonProtocol
@@ -1026,7 +1026,7 @@ def __init__(
10261026
# Backwards compatibility: the loop parameter used to be supported.
10271027
loop: Optional[asyncio.AbstractEventLoop] = kwargs.pop("loop", None)
10281028
if loop is None:
1029-
loop = asyncio_get_running_loop()
1029+
loop = asyncio.get_event_loop()
10301030
else:
10311031
warnings.warn("remove loop argument", DeprecationWarning)
10321032

0 commit comments

Comments
 (0)