Skip to content

Commit 90c600c

Browse files
author
Ralf Schlatterbeck
committed
Real handling of network errors.
Fix for correctly ignoring net errors: It seems that (at least in my installed Debian version of python2.4) socket.error does not have an errno attribute but is simply a tuple of (errno, strerror). So we now try to get errno first and if this fails we try to use err [0]. This works for a simple test-script to which I can connect with telnet on port 4711 -- it will correctly detect errno.EPIPE if I terminate the telnet session: #!/usr/bin/python2.4 import socket import errno from SocketServer import TCPServer, BaseRequestHandler class Server (BaseRequestHandler) : def handle (self) : self.file = self.request.makefile () try : while True : print >> self.file, "Testing..." except socket.error, err : print getattr (err, 'errno', "Has no errno") print err [0] print err [0] == errno.EPIPE raise # end def handle # end class Server server_address = ('', 4711) s = TCPServer (server_address, Server) s.serve_forever () Sorry for the verbose log-message but I hope to document my debugging activities
1 parent 0cc085b commit 90c600c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

roundup/cgi/client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: client.py,v 1.232 2007-01-15 21:10:26 schlatterbeck Exp $
1+
# $Id: client.py,v 1.233 2007-01-16 10:16:08 schlatterbeck Exp $
22

33
"""WWW request handler (also used in the stand-alone server).
44
"""
@@ -848,6 +848,11 @@ def _socket_op(self, call, *args, **kwargs):
848848
call(*args, **kwargs)
849849
except socket.error, err:
850850
err_errno = getattr (err, 'errno', None)
851+
if err_errno is None:
852+
try:
853+
err_errno = err[0]
854+
except TypeError:
855+
pass
851856
if err_errno not in self.IGNORE_NET_ERRORS:
852857
raise
853858

0 commit comments

Comments
 (0)