Fix issue #183 (CPU 100% usage)

As per it's
possible that a socket recv() call returns 0 bytes if the remote closes
the connection. In that case, recv() does not obey settimeout(): it
just doesn't block and returns zero bytes immediately, which in this
case results in an infinite loop if the transmission was incomplete.
This commit is contained in:
Pedro Gimeno 2013-07-01 07:36:22 +02:00
parent bfdb04716a
commit 95a1afb84b

View File

@ -66,7 +66,10 @@ class receiveDataThread(threading.Thread):
while True:
dataLen = len( += self.sock.recv(4096)
if len( == dataLen: # recv returns 0 bytes when the remote closes the connection
raise Exception("Remote closed the connection")
except socket.timeout:
print 'Timeout occurred waiting for data from', self.HOST + '. Closing receiveData thread. (ID:', str(id(self)) + ')'