Skip to content

Commit

Permalink
Fixed django#488 -- Fixed asyncio.set_event_loop() deprecation warning.
Browse files Browse the repository at this point in the history
asyncio.set_event_loop() is deprecated in Python 3.14 and slated for
removal in Python 3.16.

python/cpython@9fce906
  • Loading branch information
felixxm committed Jan 29, 2025
1 parent df6bd2a commit 332651e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions asgiref/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def _run_event_loop(self, loop, coro):
"""
Runs the given event loop (designed to be called in a thread).
"""
asyncio.set_event_loop(loop)
asyncio.get_event_loop_policy().set_event_loop(loop)
try:
loop.run_until_complete(coro)
finally:
Expand Down Expand Up @@ -289,7 +289,7 @@ async def gather():
loop.run_until_complete(loop.shutdown_asyncgens())
finally:
loop.close()
asyncio.set_event_loop(self.main_event_loop)
asyncio.get_event_loop_policy().set_event_loop(self.main_event_loop)

def __get__(self, parent: Any, objtype: Any) -> Callable[_P, _R]:
"""
Expand Down
4 changes: 2 additions & 2 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def test_stateless_server(server):
Clients can communicate to other client by name through server"""

loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
asyncio.get_event_loop_policy().set_event_loop(loop)
server.handle = partial(server_auto_close, fut=server.handle(), timeout=1.0)

client1 = Client(name="client1")
Expand Down Expand Up @@ -136,7 +136,7 @@ async def check_client2_behavior():
def test_server_delete_instance(server):
"""The max_applications of Server is 10. After 20 times register, application number should be 10."""
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
asyncio.get_event_loop_policy().set_event_loop(loop)
server.handle = partial(server_auto_close, fut=server.handle(), timeout=1.0)

client1 = Client(name="client1")
Expand Down

0 comments on commit 332651e

Please sign in to comment.