Skip to content

Commit

Permalink
support uvloop
Browse files Browse the repository at this point in the history
  • Loading branch information
cirospaciari committed Jun 24, 2023
1 parent a63b75e commit 375b5e0
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/socketify/loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,15 @@ def run(self, task=None):

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()

Expand Down

0 comments on commit 375b5e0

Please sign in to comment.