File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -229,6 +229,22 @@ def received_message(self, message):
229229 """
230230 pass
231231
232+ def unhandled_error (self , error ):
233+ """
234+ Called whenever a socket, or an OS, error is trapped
235+ by ws4py but not managed by it. The given error is
236+ an instance of `socket.error` or `OSError`.
237+
238+ Note however that application exceptions will not go
239+ through this handler. Instead, do make sure you
240+ protect your code appropriately in `received_message`
241+ or `send`.
242+
243+ The default behaviour of this handler is to log
244+ the error with a message.
245+ """
246+ logger .exception ("Failed to receive data" )
247+
232248 def _write (self , b ):
233249 """
234250 Trying to prevent a write operation
@@ -298,8 +314,8 @@ def once(self):
298314
299315 try :
300316 b = self .sock .recv (self .reading_buffer_size )
301- except socket .error :
302- logger . exception ( "Failed to receive data" )
317+ except ( socket .error , OSError ) as e :
318+ self . unhandled_error ( e )
303319 return False
304320 else :
305321 if not self .process (b ):
You can’t perform that action at this time.
0 commit comments