RefactoringRope/JsonServer.py

changeset 360
2b35968f3d02
parent 358
84c2fd80c949
diff -r 5e0c63a80d6a -r 2b35968f3d02 RefactoringRope/JsonServer.py
--- a/RefactoringRope/JsonServer.py	Sun May 09 14:30:51 2021 +0200
+++ b/RefactoringRope/JsonServer.py	Mon May 10 20:13:48 2021 +0200
@@ -221,12 +221,15 @@
         @type str
         @param environment dictionary of environment settings to pass
         @type dict
-        @return flag indicating a successful client start
-        @rtype bool
+        @return flag indicating a successful client start and the exit code
+            in case of an issue
+        @rtype bool, int
         """
         if interpreter == "" or not Utilities.isinpath(interpreter):
             return False
         
+        exitCode = None
+        
         proc = QProcess()
         proc.setProcessChannelMode(QProcess.ForwardedChannels)
         if environment is not None:
@@ -248,17 +251,37 @@
                 timer = QTimer()
                 timer.setSingleShot(True)
                 timer.start(30000)           # 30s timeout
-                while (idString not in self.connectionNames()
-                       and timer.isActive()
+                while (
+                    idString not in self.connectionNames() and
+                    timer.isActive()
                 ):
                     # Give the event loop the chance to process the new
                     # connection of the client (= slow start).
                     QCoreApplication.processEvents(
                         QEventLoop.ProcessEventsFlag.ExcludeUserInputEvents)
+                    
+                    # check if client exited prematurely
+                    if proc.state() == QProcess.ProcessState.NotRunning:
+                        exitCode = proc.exitCode()
+                        proc = None
+                        self.__clientProcesses[idString] = None
+                        break
         else:
+            if proc:
+                timer = QTimer()
+                timer.setSingleShot(True)
+                timer.start(1000)           # 1s timeout
+                while timer.isActive():
+                    # check if client exited prematurely
+                    QCoreApplication.processEvents(
+                        QEventLoop.ProcessEventsFlag.ExcludeUserInputEvents)
+                    if proc.state() == QProcess.ProcessState.NotRunning:
+                        exitCode = proc.exitCode()
+                        proc = None
+                        break
             self.__clientProcess = proc
         
-        return proc is not None
+        return proc is not None, exitCode
     
     def stopClient(self, idString=""):
         """
@@ -281,7 +304,8 @@
         
         if idString:
             with contextlib.suppress(KeyError):
-                self .__clientProcesses[idString].close()
+                if self .__clientProcesses[idString] is not None:
+                    self .__clientProcesses[idString].close()
                 del self.__clientProcesses[idString]
         else:
             if self.__clientProcess is not None:

eric ide

mercurial