-
-
Notifications
You must be signed in to change notification settings - Fork 579
Description
So first of all, this is a pretty minor thing. But I'd love it if my logging weren't getting populated by a bunch of spurious "Exception in connection handler" when I'm gracefully closing my event loop using task cancellation.
An example "log pollution":
ERROR:websockets.server:Exception in connection handler
Traceback (most recent call last):
File "C:\Python35\lib\site-packages\websockets\server.py", line 78, in handler
yield from self.ws_handler(self, path)
File "C:\Python35\lib\asyncio\coroutines.py", line 105, in __next__
return self.gen.send(None)
File "c:\py_hypergolix\hypergolix\comms.py", line 167, in _handle_connection
msg = await websocket.recv()
File "C:\Python35\lib\site-packages\websockets\protocol.py", line 266, in recv
loop=self.loop, return_when=asyncio.FIRST_COMPLETED)
File "C:\Python35\lib\asyncio\tasks.py", line 341, in wait
return (yield from _wait(fs, timeout, return_when, loop))
File "C:\Python35\lib\asyncio\tasks.py", line 424, in _wait
yield from waiter
File "C:\Python35\lib\asyncio\futures.py", line 358, in __iter__
yield self # This tells Task to wait for completion.
File "C:\Python35\lib\asyncio\tasks.py", line 290, in _wakeup
future.result()
File "C:\Python35\lib\asyncio\futures.py", line 266, in result
raise CancelledError
concurrent.futures._base.CancelledError
Note that this is strictly a problem for logging; the tasks themselves need to have the error thrown as appropriate to actually cancel the tasks, and then eventually close the client/server. But it then muddies up the logs, which again, is a relatively minor thing, but still important.
I'm also open to other options -- perhaps a CancelledError should be caught and then throw a ConnectionClosed error? But it seems to me like it's appropriate to still separate these, even if Websockets treats them similarly behind the scenes.
Thanks!