From 375b5e0d142f5723661c9c1dcd5adaa90b0868f0 Mon Sep 17 00:00:00 2001 From: cirospaciari Date: Sat, 24 Jun 2023 17:12:08 -0300 Subject: [PATCH] support uvloop --- src/socketify/loop.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/socketify/loop.py b/src/socketify/loop.py index 9b74613..074d577 100644 --- a/src/socketify/loop.py +++ b/src/socketify/loop.py @@ -129,8 +129,15 @@ class Loop: def run_once(self): # run one step of asyncio - self.loop._stopping = True - self.loop._run_once() + # if loop._run_once is not available use loop.run_forever + loop.call_soon(loop.stop) + # this is useful when using uvloop or custom loops + try: + self.loop._stopping = True + self.loop._run_once() + except Exception: + # this can be _StopError with means we should not call run_forever, but we can ignore it + self.loop.call_soon(self.loop.stop) + self.loop.run_forever() # run one step of libuv self.uv_loop.run_once()