From 227e9339b581d0ac1da0e6f76a5cc13b7760186d Mon Sep 17 00:00:00 2001 From: Ryu juheon Date: Tue, 18 Jan 2022 21:37:21 +0900 Subject: [PATCH 1/2] fix: deprecation warning in ``asyncio.wait`` close #2377 --- sanic/server/websockets/impl.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sanic/server/websockets/impl.py b/sanic/server/websockets/impl.py index ed0d7fed81..7d3eb787bf 100644 --- a/sanic/server/websockets/impl.py +++ b/sanic/server/websockets/impl.py @@ -518,8 +518,12 @@ async def recv(self, timeout: Optional[float] = None) -> Optional[Data]: ) try: self.recv_cancel = asyncio.Future() + tasks = ( + self.recv_cancel, + asyncio.create_task(self.assembler.get(timeout)), + ) done, pending = await asyncio.wait( - (self.recv_cancel, self.assembler.get(timeout)), + tasks, return_when=asyncio.FIRST_COMPLETED, ) done_task = next(iter(done)) @@ -570,8 +574,12 @@ async def recv_burst(self, max_recv=256) -> Sequence[Data]: self.can_pause = False self.recv_cancel = asyncio.Future() while True: + tasks = ( + self.recv_cancel, + asyncio.create_task(self.assembler.get(timeout=0)), + ) done, pending = await asyncio.wait( - (self.recv_cancel, self.assembler.get(timeout=0)), + tasks, return_when=asyncio.FIRST_COMPLETED, ) done_task = next(iter(done)) From d13a11b2aa7cf466df6a11778f5efcaa7466ef91 Mon Sep 17 00:00:00 2001 From: Ryu juheon Date: Wed, 19 Jan 2022 12:54:45 +0900 Subject: [PATCH 2/2] fix: change to ensure_future --- sanic/server/websockets/impl.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sanic/server/websockets/impl.py b/sanic/server/websockets/impl.py index 7d3eb787bf..aaccfaca73 100644 --- a/sanic/server/websockets/impl.py +++ b/sanic/server/websockets/impl.py @@ -520,7 +520,7 @@ async def recv(self, timeout: Optional[float] = None) -> Optional[Data]: self.recv_cancel = asyncio.Future() tasks = ( self.recv_cancel, - asyncio.create_task(self.assembler.get(timeout)), + asyncio.ensure_future(self.assembler.get(timeout)), ) done, pending = await asyncio.wait( tasks, @@ -576,7 +576,7 @@ async def recv_burst(self, max_recv=256) -> Sequence[Data]: while True: tasks = ( self.recv_cancel, - asyncio.create_task(self.assembler.get(timeout=0)), + asyncio.ensure_future(self.assembler.get(timeout=0)), ) done, pending = await asyncio.wait( tasks,