Skip to content

Commit

Permalink
Replaced get_event_loop with get_running_loop (Fixes #384)
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Nov 25, 2024
1 parent 08ea5ad commit a6e5d92
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/engineio/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async def _handler(): # pragma: no cover
for task in tasks:
task.cancel()
await asyncio.gather(*tasks, return_exceptions=True)
asyncio.get_event_loop().stop()
asyncio.get_running_loop().stop()

asyncio.ensure_future(_handler())

Expand Down Expand Up @@ -109,7 +109,7 @@ async def connect(self, url, headers=None, transports=None,
if self.handle_sigint and not async_signal_handler_set and \
threading.current_thread() == threading.main_thread():
try:
asyncio.get_event_loop().add_signal_handler(
asyncio.get_running_loop().add_signal_handler(
signal.SIGINT, async_signal_handler)
except NotImplementedError: # pragma: no cover
self.logger.warning('Signal handler is unsupported')
Expand Down
3 changes: 2 additions & 1 deletion src/engineio/async_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ async def run_sync_handler():

async def _service_task(self): # pragma: no cover
"""Monitor connected clients and clean up those that time out."""
loop = asyncio.get_running_loop()
self.service_task_event = self.create_event()
while not self.service_task_event.is_set():
if len(self.sockets) == 0:
Expand Down Expand Up @@ -569,7 +570,7 @@ async def _service_task(self): # pragma: no cover
self.logger.info('service task canceled')
break
except:
if asyncio.get_event_loop().is_closed():
if loop.is_closed():
self.logger.info('event loop is closed, exiting service '
'task')
break
Expand Down

0 comments on commit a6e5d92

Please sign in to comment.