Dealing with network failures elegantly

44 views
Skip to first unread message

Ed French

unread,
Jan 29, 2015, 4:16:53 AM1/29/15
to ws...@googlegroups.com
Hi,

I've slung together a basic Slack notifier using ws4py and I'm pretty happy with it, however, when the network goes down, the thread crashes and I get various errors that I'd like to handle elegantly (below).

I can't see how/where I can add a try except to deal with them as the threadedclient runs it's own thread?

Am I missing something?

Thanks

Ed

Two example errors:



<LogRecord: ws4py, 40, C:\Python27\lib\site-packages\ws4py\websocket.py, 302, "Failed to receive data">
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\ws4py\websocket.py", line 300, in once
    b = self.sock.recv(self.reading_buffer_size)
  File "C:\Python27\lib\ssl.py", line 246, in recv
    return self.read(buflen)
  File "C:\Python27\lib\ssl.py", line 165, in read
    return self._sslobj.read(len)
error: [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time or established connection failed because connected host has failed to respond
icon clicked


and


Exception in thread Thread-1:
Traceback (most recent call last):
  File "C:\Python27\lib\threading.py", line 810, in __bootstrap_inner
    self.run()
  File "C:\Python27\lib\site-packages\ws4py\websocket.py", line 55, in run
    self.websocket.send(PongControlMessage(data='beep'))
  File "C:\Python27\lib\site-packages\ws4py\websocket.py", line 265, in send
    self._write(data)
  File "C:\Python27\lib\site-packages\ws4py\websocket.py", line 241, in _write
    raise RuntimeError("Cannot send on a terminated websocket")
RuntimeError: Cannot send on a terminated websocket



Sylvain Hellegouarch

unread,
Jan 29, 2015, 5:08:52 AM1/29/15
to ws...@googlegroups.com
Hello Ed,

ws4py's error handling has a lot to improve unfortunately. I'm torn between a catch-all solution or a more specific approach. But, in that latter case, this could make the API quite complicated. So, maybe a catchall with a callback to your websocket sub-class would do?

--

Ed French

unread,
Jan 29, 2015, 7:26:39 AM1/29/15
to ws...@googlegroups.com
That sounds like a perfect solution,
Thanks
Ed

--
You received this message because you are subscribed to a topic in the Google Groups "ws4py" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ws4py/MO3Pk5AH4Vo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ws4py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Edward French

Reply all
Reply to author
Forward
0 new messages