Added some code to handle error conditions. server

Tue, 13 Feb 2024 11:17:38 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 13 Feb 2024 11:17:38 +0100
branch
server
changeset 10567
b098e0d028cc
parent 10566
25330d3ea3af
child 10568
399d81a784a4

Added some code to handle error conditions.

src/eric7/RemoteServer/EricServer.py file | annotate | diff | comparison | revisions
src/eric7/RemoteServer/EricServerDebuggerRequestHandler.py file | annotate | diff | comparison | revisions
src/eric7/RemoteServerInterface/EricServerInterface.py file | annotate | diff | comparison | revisions
--- a/src/eric7/RemoteServer/EricServer.py	Tue Feb 13 09:50:09 2024 +0100
+++ b/src/eric7/RemoteServer/EricServer.py	Tue Feb 13 11:17:38 2024 +0100
@@ -288,16 +288,18 @@
         self.__selector.unregister(self.__socket)
         self.__socket.shutdown(socket.SHUT_RDWR)
         self.__socket.close()
+        self.__socket = None
 
     def __shutdown(self):
         """
         Private method to shut down the server.
         """
-        self.__closeIdeConnection()
+        self.__closeIdeConnection(shutdown=True)
 
         print("Stop listening for 'eric-ide' connections.")
-        self.__socket.shutdown(socket.SHUT_RDWR)
-        self.__socket.close()
+        if self.__socket is not None:
+            self.__socket.shutdown(socket.SHUT_RDWR)
+            self.__socket.close()
 
         self.__selector.close()
 
@@ -326,7 +328,7 @@
             )
             connection.close()
 
-    def __closeIdeConnection(self):
+    def __closeIdeConnection(self, shutdown=False):
         """
         Private method to close the connection to an eric-ide.
         """
@@ -345,7 +347,8 @@
 
             self.__debuggerRequestHandler.shutdownClients()
 
-        self.__initializeIdeSocket()
+        if not shutdown:
+            self.__initializeIdeSocket()
 
     def __serviceIdeConnection(self, key):
         """
--- a/src/eric7/RemoteServer/EricServerDebuggerRequestHandler.py	Tue Feb 13 09:50:09 2024 +0100
+++ b/src/eric7/RemoteServer/EricServerDebuggerRequestHandler.py	Tue Feb 13 11:17:38 2024 +0100
@@ -115,8 +115,7 @@
             address=address,
             handler=self.__serviceDbgClientConnection,
         )
-        events = selectors.EVENT_READ
-        self.__server.getSelector().register(connection, events, data=data)
+        self.__server.getSelector().register(connection, selectors.EVENT_READ, data=data)
 
     def __serviceDbgClientConnection(self, key):
         """
@@ -200,22 +199,6 @@
             params={"debugger_id": self.__mainClientId if self.__mainClientId else ""},
         )
 
-    def __serviceDbgClientStdoutStderr(self, key):
-        """
-        Private method to service the debug client stdout and stderr channels.
-        
-        @param key reference to the SelectorKey object associated with the connection
-            to be serviced
-        @type selectors.SelectorKey
-        """
-        data = key.fileobj.read()
-        if key.data.name == "debug_client_stdout":
-            # TODO: stdout handling not implemented yet
-            print("stdout:", data)
-        elif key.data.name == "debug_client_stderr":
-            # TODO: stderr handling not implemented yet
-            print("stderr:", data)
-
     def shutdownClients(self):
         """
         Public method to shut down all connected clients.
@@ -290,12 +273,7 @@
         """
         self.__inStartClient = True
 
-        # 1. stop an already started debug client
-        if self.__client is not None:
-            # TODO: unregister stdin & stderr
-            pass
-
-        # 2. start a debug client
+        # start a debug client
         debugClient = os.path.abspath(
             os.path.join(
                 os.path.dirname(__file__),
@@ -313,9 +291,6 @@
         self.__client = subprocess.Popen(
             args, stdout=subprocess.PIPE, stderr=subprocess.PIPE
         )
-        # TODO: register stdin & stderr with selector
-
-        self.__inStartClient = False
 
     def __stopClient(self, params):  # noqa: U100
         """
--- a/src/eric7/RemoteServerInterface/EricServerInterface.py	Tue Feb 13 09:50:09 2024 +0100
+++ b/src/eric7/RemoteServerInterface/EricServerInterface.py	Tue Feb 13 11:17:38 2024 +0100
@@ -247,6 +247,9 @@
                 maxSize = length - len(data)
                 if self.__connection.bytesAvailable() < maxSize:
                     self.__connection.waitForReadyRead(50)
+                if not self.__connection:
+                    # connection to server is gone uncontrolled
+                    break
                 newData = self.__connection.read(maxSize)
                 if newData:
                     data += newData

eric ide

mercurial