From: Charlie G. <cha...@gm...> - 2007-07-31 05:37:10
|
I just committed a version of test_select_new that reliably passes for me, but I'm a little confused as to why one of the changes made a difference. test_select_new has several tests that fill up the outbound buffer on a socket and then empty it from the other side while using select to see where data is available. This is the method that does the reading: def read_inchannel(self, expected): results = "" start = time.time() while 1: if self.select_readable(): recvd_bytes = self.socket.recv(expected - len(results)) if len(recvd_bytes): results += recvd_bytes if len(results) == expected: return results else: stop = time.time() if (stop - start) > READ_TIMEOUT: raise Exception("Got %d bytes but %d bytes were written." % (len(results), expected)) self.socket is just a socket object from the socket module. self.select_readable just calls select.select([self.socket], [], [], SELECT_TIMEOUT). The change I made was to move SELECT_TIMEOUT from 0 to .2. With SELECT_TIMEOUT at its old value, all of the reading tests would get all of the data out and pass except for the last one. The difference in the last test is that it fills up outbound buffers on both a client and server socket, and empties them one after another. The rest of the tests just do one or the other. The last emptied socket will read part of the data after which self.select_readable() never returns an available socket even though there should be more data available. It attempts to select on that socket many many times before the READ_TIMEOUT is reached and it raises the exception at the end of read_inchannel. If I remove the exception and call self.select_readable right outside of that code, it successfully finds that the socket has data available. After changing the SELECT_TIMEOUT to .2 the test has succeeded every time I've tried it. I can't see why that would make any difference though. I could see if instead of having the while loop operate on 1 I looped over if the socket was readable how upping the timeout would make a difference. However, the code tries the select 100s of times before the READ_TIMEOUT is reached, so it seems like that should be equivalent to me. What am I missing? Charlie |