我正在使用cherrypy和ws4py。
如果浏览器切断了websocket连接,则def received_message(self, m):
中的任何写入都会引发错误,
Exception in thread Thread-1:
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "/Library/Python/2.7/site-packages/ws4py/manager.py", line 310, in run
if not ws.once():
File "/Library/Python/2.7/site-packages/ws4py/websocket.py", line 388, in once
if not self.process(b):
File "/Library/Python/2.7/site-packages/ws4py/websocket.py", line 445, in process
self.close(s.closing.code, s.closing.reason)
File "/Library/Python/2.7/site-packages/ws4py/websocket.py", line 189, in close
self._write(self.stream.close(code=code, reason=reason).single(mask=self.stream.always_mask))
File "/Library/Python/2.7/site-packages/ws4py/websocket.py", line 279, in _write
self.sock.sendall(b)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
error: [Errno 32] Broken pipe
如何判断连接是否已关闭?