Select weirdness

Ron Garret rNOSPAMon at flownet.com
Sun Apr 22 20:42:10 CEST 2007


I think I've figured out what's going on.

First, here's the smoking gun: I changed the code as follows:

class myHandler(StreamRequestHandler):
  def handle(self):
    print '>>>>>>>>>>>'
    while 1:
      sl = select([self.rfile],[],[],1)[0]
      print sl
      l = self.rfile.readline()
      if len(l)<3: break
      print l,
      pass

(Rest of code is unchanged.)

In other words, I select on the rfile object and added a timeout.

Here's the result when I cut-and-paste an HTTP request:

>>>>>>>>>>>
[<socket._fileobject object at 0x6b110>]
GET /foo/baz HTTP/1.1
[<socket._fileobject object at 0x6b110>]
Accept: */*
[<socket._fileobject object at 0x6b110>]
Accept-Language: en
[<socket._fileobject object at 0x6b110>]
Accept-Encoding: gzip, deflate
[<socket._fileobject object at 0x6b110>]
Cookie: c1=18:19:55.042196; c2=18:19:55.042508
[]
User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) 
AppleWebKit/419 (KHTM
[]
L, like Gecko) Safari/419.3
[]
Connection: keep-alive
[]
Host: localhost:8081
[]
<<<<<<<<<<<<

As you can see, the select call shows input available for a while (five 
lines) and then shows no input available despite the fact that there is 
manifestly still input available.

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

So... is this a bug in select?  Or a bug in my code?

rg



More information about the Python-list mailing list