eric7/E5Network/E5JsonClient.py

branch
eric7
changeset 8327
666c2b81cbb7
parent 8312
800c432b34c8
diff -r 547319e56c60 -r 666c2b81cbb7 eric7/E5Network/E5JsonClient.py
--- a/eric7/E5Network/E5JsonClient.py	Wed May 19 18:16:45 2021 +0200
+++ b/eric7/E5Network/E5JsonClient.py	Wed May 19 19:53:36 2021 +0200
@@ -155,3 +155,49 @@
         with contextlib.suppress(socket.error, OSError):
             self.__connection.shutdown(socket.SHUT_RDWR)
             self.__connection.close()
+    
+    def poll(self, waitMethod=""):
+        """
+        Public method to check and receive one message (if available).
+        
+        @param waitMethod name of a method to wait for
+        @type str
+        @return dictionary containing the data of the waited for method
+        @rtype dict
+        """
+        try:
+            if waitMethod:
+                rrdy, wrdy, xrdy = select.select(
+                    [self.__connection], [], [])
+            else:
+                rrdy, wrdy, xrdy = select.select(
+                    [self.__connection], [], [], 0)
+            
+            if self.__connection in rrdy:
+                method, params = self.__receiveJson()
+                if method is not None:
+                    if method == "Exit":
+                        self.__exitClient = True
+                    elif method == waitMethod:
+                        return params
+                    else:
+                        self.handleCall(method, params)
+        
+        except (select.error, KeyboardInterrupt, socket.error):
+            # just ignore these
+            pass
+        
+        except Exception:
+            exctype, excval, exctb = sys.exc_info()
+            tbinfofile = io.StringIO()
+            traceback.print_tb(exctb, None, tbinfofile)
+            tbinfofile.seek(0)
+            tbinfo = tbinfofile.read()
+            del exctb
+            self.sendJson("ClientException", {
+                "ExceptionType": str(exctype),
+                "ExceptionValue": str(excval),
+                "Traceback": tbinfo,
+            })
+        
+        return None

eric ide

mercurial