select.select and socket.setblocking
Grant Edwards
grante at visi.com
Tue Dec 30 15:41:17 EST 2008
On 2008-12-30, Francesco Bochicchio <bockman at virgilio.it> wrote:
> 3. AFAIK (sorry, I feel acronym-ly today ;), there is no difference in
> select between blocking and non-blocking mode. The difference is in the
> recv (again, assuming that you use TCP as protocol, that is AF_INET,
> SOCK_STREAM), which in the blocking case would wait to receive all the
> bytes that you requested,
No, in blocking mode it will wait to receive _some_ data (1 or
more bytes). The "requested" amount is strictly an upper
limit: recv won't return more than the requested number of
bytes, but it might return less.
In non-blocking mode, it will always return immediately, either
with some data, no data (other end closed), or an EAGAIN or
EWOULDBLOCK error (I forget which).
> [...] I myself tend to avoid using non-blocking sockets, since
> blocking sockets are much easier to handle...
That depends on whether you can tolerate blocking or not. In
an event-loop, blocking is generally not allowed.
--
Grant
More information about the Python-list
mailing list