Skip to content

Commit

Permalink
Reuse the aiohttp client session on reconnects (Fixes #226)
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Aug 20, 2021
1 parent 9246c54 commit 3c8fdfe
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/engineio/asyncio_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,17 @@ def create_event(self):
"""Create an event object."""
return asyncio.Event()

def _reset(self):
if self.http: # pragma: no cover
asyncio.ensure_future(self.http.close())
super()._reset()
def __del__(self): # pragma: no cover
# try to close the aiohttp session if it is still open
if self.http and not self.http.closed:
try:
loop = asyncio.get_event_loop()
if loop.is_running():
loop.ensure_future(self.http.close())
else:
loop.run_until_complete(self.http.close())
except:
pass

async def _connect_polling(self, url, headers, engineio_path):
"""Establish a long-polling connection to the Engine.IO server."""
Expand Down

0 comments on commit 3c8fdfe

Please sign in to comment.