Bug in select (was: Re: Select weirdness)

Ron Garret rNOSPAMon at flownet.com
Sun Apr 22 16:58:21 EDT 2007


In article <rNOSPAMon-934744.11420922042007 at news.gha.chartermi.net>,
 Ron Garret <rNOSPAMon at flownet.com> wrote:

> The answer is obvious: select is looking only at the underlying socket, 
> and not at the rfile buffers.

Here is conclusive proof that there's a bug in select:

from socket import *
from select import select
s=socket(AF_INET, SOCK_STREAM)
s.bind(('',8080))
s.listen(5)
f = s.accept()[0].makefile()
# Now telnet to port 8080 and enter two lines of random text
f.readline()
select([f],[],[],1)
f.readline()

Here's the sample input:

[ron at mickey:~/devel/sockets]$ telnet localhost 8081
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
123
321


And this is the result:

>>> f.readline()
'123\r\n'
>>> select([f],[],[],1)
# After one second...
([], [], [])
>>> f.readline()
'321\r\n'
>>> 


So this is clearly a bug, but surely I'm not the first person to have 
encountered this?  Is there a known workaround?

rg



More information about the Python-list mailing list