-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document select() failure with buffered file #44883
Comments
|
select.select fails on file-like objects created by socket.makefile when data exists in the file buffer but not in the underlying socket. Here is code to reproduce the bug. Run it, then point a web browser at port 8080 and observer that select times out indicating that no input is available even though input is still in fact available. ======= from SocketServer import *
from socket import *
from select import select
class myHandler(StreamRequestHandler):
def handle(self):
while 1:
sl = select([self.rfile],[],[],1)[0]
print sl
l = self.rfile.readline()
if len(l)<3: break
print l,
pass
print>>self.wfile, 'HTTP/1.0 200 OK'
print>>self.wfile, 'Content-type: text/plain'
print>>self.wfile
print>>self.wfile, 'foo'
server = TCPServer(('',8080), myHandler)
server.serve_forever() |
|
The handler should not do its own select() call. (And even then, select should use the underlying socket, not the wrapping pseudo-file object). |
For this simple example yes, not for more complicated cases. My particular application is a transparent HTTP proxy which needs to be able to serve multiple connections at once and handle keep-alive connections. (The proxy connects to local server processes through unix sockets, which is why I can't use a regular HTTP proxy. Send me email if you want more details about why I'm doing this.) Without writing a full-blown HTTP-aware proxy, select (or something like it) is necessary. Upon further study, though, I have come to the conclusion that this is not actually a bug (since select is doing what it is advertised to do), just very counter-intituitive behavior. If select is going to accept file objects as arguments it ought to do the Right Thing with them IMO. |
|
Cannot verify for trunk. |
|
This older post IMO it should be documented that select() does not work so well for |
|
I've changed things in reply to msg85311, feel free to alter things again if you disagree. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: