"Alan Kennedy" <python-dev at alan.kennedy.name> wrote: [snip] > def create_connection(address, timeout=sentinel): > [snip] > if timeout != sentinel: > new_socket.settimeout(timeout) > if new_socket.gettimeout() == 0: > result = new_socket.connect_ex(address) > else: > new_socket.connect(address) > result = new_socket > [snip] > > I know that this makes it all more complex, and I'm *not* saying the > new function should be modified to include these concerns. [snip] But now the result could be either an error code OR a socket. One of the reasons to provide a timeout for the create_connection call, if I understand correctly, is to handle cases for which you don't get a response back in sufficient time. If the user provides zero as a timeout, then they may very well get an exception, which is what they should expect. Then again, even with an arbitrary timeout, an exception is possible (especially if a host is down, etc.), and hiding the exceptional condition (didn't connect in the allotted time) is a bad thing. - Josiah
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4