Steve Holden wrote: > [EMAIL PROTECTED] wrote: > > Hi, > > > > I'm building a multithreaded application and I encountered a tiny and > > annoying problem. I use a select to wait for data to be read from a > > socket, after some reads, the select simply blocks and stays that way > > until I close the connection on the other side of the socket. When the > > socket is closed on the writer end the select releases and then I get > > only empty strings from the socket. > > That's to be expected: the first return of a zero-length string from > socket.read() indicates end of file. > > > My question is this: Why did it block? The reading has never ended, > > every test I make I write 50 requests (wich are strings) to the socket > > and I have read the maximum of 34 requests. I'm using winPdb to take a > > closer look on what's happening and I see the threads blocked on this > > same select. If I send anything more through the socket, the select > > releases for a thread, despite the other data that is still unread. > > > Are you sure that the received data is presenting in block the same size > as are being sent? There's no guarantee this will be so on a TCP socket, > and it may be that multiple sends are being coalesced into a single > read. The important thing to focus on is the total number of bytes sent > and received.
Well, actually I´m using a very simple protocol wich sends only strings ended by newline. I need to send 3 chunks of information and a newline after them. On the reader side I make 3 readline(), this way I wouldn´t have to care about this problem, but maybe that´s where I´m falling. If that´s the case, I´ll have to use a more complex protocol. > > > This is the select: > > rd,w,e = select.select([self.rfd],[],[]) > > > > self.rfd is the fileno of the file object returned by the makefile > > method from the socket object. > > > It would be simpler to use the result of the socket's .fileno() method > directly. > Yes, you are right, this is something remanescent from old ideas. > > I know that's some buffer behavior that I'm missing but I don't know > > what it is. > > > > anything is helpfull, If I'm beeing stupid you can say it. > > thanks > > > Without being able to see all your code it's hard to say whether or not > you are doing something daft, but you give a general impression of > competence. > Thanks, the code has a significant size now, if I don´t solve it quickly I´ll post the most important parts. thanks again, Andre LS Meirelles > regards > Steve > -- > Steve Holden +44 150 684 7255 +1 800 494 3119 > Holden Web LLC/Ltd http://www.holdenweb.com > Love me, love my blog http://holdenweb.blogspot.com > Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list