[Python-Dev] Changing select.select to accept iterables (original) (raw)

Brett C. bac at OCF.Berkeley.EDU
Sat Sep 6 23:32:25 EDT 2003


Guido van Rossum wrote:

[Brett, about <http://www.python.org/sf/798046>] Since Tim thinks it's okay to change (and since I now know what the OP wanted) you have my blessing to give this a try.

OK, done. I tore out the PyList_Check in select_select() and just put the PySequence_Fast() call in list2set(), which I renamed seq2set(), so as to centralize the code and make managing refcounts simpler. I pasted in an interpreter session at the end of this email showing some checking I did to make sure I didn't botch anything. If someone could double-check them and see if they can think of something I may have missed I would appreciate it.

I made the docstring (as seen below) say that the arguments must be sequences since that is what PySequence_Fast says it takes in, although it obviously works with containers. Any objections?

Assuming no one can think of anything that I missed I will then commit (with appropriate Misc/NEWS and doc changes), change the bug report to an feature request since that is what it really is, and close it.

-Brett

[passes test_select...]

import test.test_select timeout = 0 'testing...\n' timeout = 1 'testing...\n' timeout = 2 'testing...\n' timeout = 4 'testing...\n' timeout = 8 'testing...\n' timeout = 16 'testing...\n' timeout = None 'testing...\n' timeout = None 'testing...\n' timeout = None 'testing...\n' timeout = None 'testing...\n' timeout = None '' EOF [24363 refs]

[works with sets as requested...]

from sets import Set [26557 refs] from select import select [26559 refs] read_FILE = file("README", 'r') [26567 refs] write_FILE = file("@test", 'w') [26574 refs] print select(Set([write_FILE]), Set([read_FILE]), [], 0) ([<open file '@test', mode 'w' at 0x5051e0>], [<open file 'README', mode 'r' at 0x486550>], []) [26607 refs]

[modified docstring to say it works with sequences...]

help(select) Help on built-in function select:

select(...) select(rlist, wlist, xlist[, timeout]) -> (rlist, wlist, xlist)

 Wait until one or more file descriptors are ready for some kind of I/O.
 The first three arguments are sequences of file descriptors to be 

waited for: ...

[new error message on improper arguments...]

print select(1, 2, 3, 0) Traceback (most recent call last): File "", line 1, in ? TypeError: arguments 1-3 must be sequences [39435 refs]

[managed to not screw up refcounts =) ...]

print select(Set([write_FILE]), Set([read_FILE]), [], 0) ([<open file '@test', mode 'w' at 0x5051e0>], [<open file 'README', mode 'r' at 0x486550>], []) [39435 refs] print select(Set([write_FILE]), Set([read_FILE]), [], 0) ([<open file '@test', mode 'w' at 0x5051e0>], [<open file 'README', mode 'r' at 0x486550>], []) [39435 refs]

[... and of course still works the way it originally did.]

print select([write_FILE], [read_FILE], [], 0) ([<open file '@test', mode 'w' at 0x5051e0>], [<open file 'README', mode 'r' at 0x486550>], []) [39435 refs]



More information about the Python-Dev mailing list