[Python-Dev] Minor socket timeout quibble - timeout raises socket.error

Steve Holden sholden@holdenweb.com
Tue, 25 Jun 2002 12:21:48 -0400

----- Original Message -----
From: "Skip Montanaro" <skip@pobox.com>
To: <python-dev@python.org>
Sent: Monday, June 24, 2002 9:53 PM
Subject: [Python-Dev] Minor socket timeout quibble - timeout raises

> I just noticed in the development docs that when a timeout on a socket
> occurs, socket.error is raised.  I rather liked the idea that a different
> exception was raised for timeouts (I used Tim O'Malley's timeout_socket
> module).  Making a TimeoutError exception a subclass of socket.error would
> be fine so you can catch it with existing code, but I could see recovering
> differently for a timeout as opposed to other possible errors:
>     sock.settimeout(5.0)
>     try:
>         data = sock.recv(8192)
>     except socket.TimeoutError:
>         # maybe requeue the request
>         ...
>     except socket.error, codes:
>         # some more drastic solution is needed
>         ...

This seems logical: the timeout is inherently different, so a separate
"except" seems better than having to analyze the reason of the socket error.

Steve Holden                                 http://www.holdenweb.com/
Python Web Programming                http://pydish.holdenweb.com/pwp/