Bugfix to avoid hanging Eric5 on shutdown. BgService

Fri, 28 Mar 2014 23:10:00 +0100

author
T.Rzepka <Tobias.Rzepka@gmail.com>
date
Fri, 28 Mar 2014 23:10:00 +0100
branch
BgService
changeset 3444
118cb489304d
parent 3443
7d919fd299f6
child 3445
bf95eac5ce12

Bugfix to avoid hanging Eric5 on shutdown.

Utilities/BackgroundClient.py file | annotate | diff | comparison | revisions
--- a/Utilities/BackgroundClient.py	Thu Mar 27 23:03:40 2014 +0100
+++ b/Utilities/BackgroundClient.py	Fri Mar 28 23:10:00 2014 +0100
@@ -74,28 +74,34 @@
         self.connection.sendall(header)
         self.connection.sendall(packedData)
 
+    def __receive(self, length):
+        """
+        Private methode to receive the given length of bytes.
+        
+        @param length bytes to receive (int)
+        @return received bytes or None if connection closed (str)
+        """
+        data = b''
+        while len(data) < length:
+            newData = self.connection.recv(length - len(data))
+            if not newData:
+                return None
+            data += newData
+        return data
+    
     def run(self):
         """
         Implement the main loop of the client.
         """
         try:
             while True:
-                try:
-                    header = b''
-                    while len(header) < 8:
-                        header += self.connection.recv(8 - len(header))
-                except socket.error:
-                    # Leave main loop if connection was closed.
-                    break
+                header = self.__receive(8)
                 # Leave main loop if connection was closed.
                 if not header:
                     break
                 
                 length, datahash = struct.unpack(b'!II', header)
-                packedData = b''
-                while len(packedData) < length:
-                    packedData += self.connection.recv(
-                        length - len(packedData))
+                packedData = self.__receive(length)
                 
                 assert adler32(packedData) & 0xffffffff == datahash, \
                     'Hashes not equal'

eric ide

mercurial