Skip to content

Commit

Permalink
catch cancelled tasks due to client leaving
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Feb 7, 2017
1 parent 5796794 commit 3abadf1
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions engineio/asyncio_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,13 @@ async def _handle_connect(self, environ, transport, b64=False):

async def _trigger_event(self, event, *args, **kwargs):
"""Invoke an event handler."""
ret = None
if event in self.handlers:
if asyncio.iscoroutinefunction(self.handlers[event]):
await self.handlers[event](*args)
try:
ret = await self.handlers[event](*args)
except asyncio.CancelledError:
pass
else:
self.handlers[event](*args)
ret = self.handlers[event](*args)
return ret

0 comments on commit 3abadf1

Please sign in to comment.