# problemReport.py import socket import threading class ListenerThread(threading.Thread): def setConnection(self, conn): self.conn = conn def recv(self, length): buffer = '' while len(buffer) < length: try: prevLen = len(buffer) buffer += self.conn.recv(length - len(buffer)) if len(buffer) == prevLen: # From what I can tell this will only happen if the far end # closes the connection. I would have expected some kind of # exception... break except socket.timeout,e: # If the recv times out ... just keep going pass if len(buffer) < length: # Something has gone wrong ... didn't get all the data we expected. raise socket.error() return buffer def run(self): while True: try: data = self.revc(4) print "got data" # ... except socket.error: break class Problem(object): def __init__(self): self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.s.connect(('',12345)) self.s.settimeout(0.25) self.listenerThread = ListenerThread() self.listenerThread.setConnection(self.s) self.listenerThread.setDaemon(True) #Commenting out the next line seems to 'fix' the problem self.listenerThread.start() def send(self, bytesToSend): bytesSent = 0 import time tic = time.time() while bytesSent < len(bytesToSend): bytesSent += self.s.send(bytesToSend[bytesSent:]) toc = time.time() print 'send %d bytes in %f seconds'%(len(bytesToSend),toc-tic) p = Problem() p.send('helo') p.send('A'*192) ############################################################################## ##################### Below is the contents of byteSink.py ################### ### I am placing it here because I can't quickly figure out how to attach #### ### multiple files to a jython bug report. Please CUT/paste this part before # ### running ################################################################## ############################################################################## # byteSink.py import socket sListen = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sListen.bind( ('', 12345) ) while True: sListen.listen(1) s,addr = sListen.accept() print "Accepted from ",addr while True: buf = s.recv(4096) if len(buf) == 0: print "Lost connection" break print "Rxed %d bytes: %s"%(len(buf), buf)