Re: select

Guido van Rossum (Guido.van.Rossum@cwi.nl)
Mon, 29 Jun 1992 11:06:15 +0200

>Has anyone created a select function similar to the select in BSD sockets?
>
>I figured you could pass a list of items in and have it return
>a 3 element tupple of the return values..

What a coincidence! About a week ago Jack and I sat together and
designed an interface for BSD select, and Jack made an implementation
of it. The interface is like this:

import select
(ready_r, ready_w, ready_e) = \
select.select(test_r, test_w, test_e, timeout)

Here test_r, test_w and test_e are lists of file or socket objects
(actually, anything with a 'fileno' method that returns a file
descriptor is possible; alternately, you may specify file descriptors
directly) and ready_{r,w,e} are similar lists containing the subset of
items from the corresponding test_* lists that are ready within the
timeout. The timeout is a floating point number in seconds (so you
can specify any fraction you like and the system will round it to the
available precision). Leaving the timeout parameter out means an
infinite time-out.

I can post or mail the patches if you like; it requires changes to
socketmodule.c and fileobject.c to add 'fileno()' methods to them.

I read the discussion on this list about an alternate design; while
that is also elegant I don't think the difference is important enough
to change the interface now that it's already been implemented...

--Guido van Rossum, CWI, Amsterdam <guido@cwi.nl>
"Rule six -- there is *no* rule six"

[Sorry Lance -- I accidentally mailed you a private copy of this...]