There's a small wart still, as far as I can see: a timeout seems likely to manifest itself in the form of a nonpositive timeout value being passed to the connection call.
That will still raise a timeout-related exception when that happens so it's not altogether wrong, but it might confuse post-mortem analysis. In my quick experiments I get “socket.error: [Errno 115] Operation now in progress” when the timeout is zero, and “ValueError: Timeout value out of range” when it's negative.
Much better approach I think, thanks.
There's a small wart still, as far as I can see: a timeout seems likely to manifest itself in the form of a nonpositive timeout value being passed to the connection call.
That will still raise a timeout-related exception when that happens so it's not altogether wrong, but it might confuse post-mortem analysis. In my quick experiments I get “socket.error: [Errno 115] Operation now in progress” when the timeout is zero, and “ValueError: Timeout value out of range” when it's negative.