Erno Kuusela erno-news at
Tue Aug 27 12:15:27 CEST 2002

In article <3D69C8F2.60507 at something.invalid>, Greg Ewing
<see_reply_address at something.invalid> writes:

| Heiko Wundram wrote:
|| # Set nonblocking and initialize data.
|| self.request.setblocking(0)

| You shouldn't be making the socket non-blocking. Select
| will return immediately for a non-blocking socket,
| whether there's data there or not.

i don't think so:

Python 2.1.3 (#1, Apr 20 2002, 10:14:34) 
[GCC 2.95.4 20011002 (Debian prerelease)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> from socket import *
>>> s = socket(AF_INET, SOCK_DGRAM)
>>> s.bind(('', 12345))
>>> s.setblocking(0)
>>> from select import select
>>> select([s], [], [], 1)
   (... one second passes ...)
([], [], [])

putting it in nonblocking mode will let you catch
programming mistakes where you accidentally do something
blocking by mistake.

also i remember reading somewhere that recv on a socket can infact
block after select has claimed it has incoming data waiting in some
weird conditions, so it is good practice to catch that case too. no
reference, sorry.  (for example, select on a listening socket, returns
readable, RST arrives, accept blocks)

  -- erno

More information about the Python-list mailing list