Digest Number 1946

Fredrik Lundh fredrik at pythonware.com
Fri Mar 23 08:01:29 CET 2001

Bill Bell wrote:
> I'm new to Python, have been playing with someone's whois client,
> which contains the following lines:
>         s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>         s.setblocking(1)
>         s.connect((self.whoisserver, 43))
> The code works fine (as long as the requested whois server is
> available) if the argument to 'setblocking' is 1. However, if I change
> this to 0 I receive the diagnostic,
> "The socket operation could not complete without blocking."
> I cannot find the code that contains this literal.

did you look in the sources for your operating system? ;-)

> Would someone please suggest what might be going wrong.

nothing's going wrong here -- the system's reminding you that
when you're using non-blocking mode, the fact that connect
returns doesn't mean that it has succeeded yet.

you're supposed to catch that exception, and check for com-
pletion using select or poll.  see your favourite socket pro-
gramming guide for more info.

Cheers /F

More information about the Python-list mailing list