python socket:[Errno 32] Broken pipe
2013-09-14 18:12
369 查看
这个错误发生在当client端close了当前与你的server端的socket连接,但是你的server端在忙着发送数据给一个已经断开连接的socket。
下面是stackoverflow给的解决方案:
Your server process has received a SIGPIPE writing to a socket. This usually happens when you write to a socket fully closed on the other (client) side. This might be happening when a client program doesn't wait till all the data from the server is received and simply closes a socket (using close function). In a C program you would normally try setting to ignore SIGPIPE signal or setting a dummy signal handler for it. In this case a simple error will be returned when writing to a closed socket. In your case a python seems to throw an exception that can be handled as a premature disconnect of the client.
下面是python的实现:
下面是stackoverflow给的解决方案:
Your server process has received a SIGPIPE writing to a socket. This usually happens when you write to a socket fully closed on the other (client) side. This might be happening when a client program doesn't wait till all the data from the server is received and simply closes a socket (using close function). In a C program you would normally try setting to ignore SIGPIPE signal or setting a dummy signal handler for it. In this case a simple error will be returned when writing to a closed socket. In your case a python seems to throw an exception that can be handled as a premature disconnect of the client.
下面是python的实现:
import socket def hack_fileobject_close(): if getattr(socket._fileobject.close, '__hacked__', None): return old_close = socket._fileobject.close def new_close(self, *p, **kw): try: return old_close(self, *p, **kw) except Exception, e: print("Ignore %s." % str(e)) new_close.__hacked__ = True socket._fileobject.close = new_close hack_fileobject_close()
相关文章推荐
- Python提示[Errno 32]Broken pipe导致线程crash错误解决方法
- Python的问题解决: IOError: [Errno 32] Broken pipe
- Python的问题解决: IOError: [Errno 32] Broken pipe
- Python提示[Errno 32]Broken pipe导致线程crash错误解决方法
- Python:[Errno 32] Broken pipe 问题
- python socket [Errno 10054]的解决方法
- python socket.gethostbyaddr socket.herror: [Errno 1] Unknown host
- python学习--for Mac 问题解决:socket.gaierror: [Errno -2] Name or service not known
- error: [Errno 32] Broken pipe
- [python爬虫]使用urllib函数urlretrieve报错[socket error][Errno 10054]
- Python 3.5 socket OSError: [Errno 101] Network is unreachable
- ERROR: openstack Error finding address for http://10.16.37.215:9292/v1/images: [Errno 32] Broken pipe
- python socket.error: [Errno 48] Address already in use
- python 远程主机强迫关闭了一个现有的连接 socket 超时设置 errno 10054
- [转] python 远程主机强迫关闭了一个现有的连接 socket 超时设置 errno 10054
- Python提示[Errno 32] Broken pipe 导致线程crash错误
- python socket 超时设置 errno 10054
- python socket 超时设置 errno10054
- 解决Python通过STMP发送邮件出现socket.error: [Errno 10061]
- Python socket.error: [Errno 98] Address already in use