Refactored some code in BackgroundService.py. eric7

Thu, 08 Sep 2022 16:41:15 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 08 Sep 2022 16:41:15 +0200
branch
eric7
changeset 9317
bf8135417cd3
parent 9316
53ab4cd68b5b
child 9318
a47b5c46be3f

Refactored some code in BackgroundService.py.

src/eric7/Utilities/BackgroundService.py file | annotate | diff | comparison | revisions
--- a/src/eric7/Utilities/BackgroundService.py	Wed Sep 07 17:38:41 2022 +0200
+++ b/src/eric7/Utilities/BackgroundService.py	Thu Sep 08 16:41:15 2022 +0200
@@ -69,16 +69,28 @@
         ## Note: Need the port if started external in debugger:
         print("Background Service listening on: {0:d}".format(port))
         # __IGNORE_WARNING__
+        
+        interpreter = self.__getPythonInterpreter()
+        if interpreter:
+            process = self.__startExternalClient(interpreter, port)
+            if process:
+                self.processes["Python3"] = process, interpreter
+
+    def __getPythonInterpreter(self):
+        """
+        Private method to generate the path of the Python interpreter to be
+        used to run the background client.
+        
+        @return path of the Python interpreter
+        @rtype str
+        """
         venvName = Preferences.getDebugger("Python3VirtualEnv")
         interpreter = (
             ericApp().getObject("VirtualEnvManager").getVirtualenvInterpreter(venvName)
         )
         if not interpreter:
             interpreter = Globals.getPythonExecutable()
-        if interpreter:
-            process = self.__startExternalClient(interpreter, port)
-            if process:
-                self.processes["Python3"] = process, interpreter
+        return interpreter
 
     def __startExternalClient(self, interpreter, port):
         """
@@ -277,12 +289,7 @@
         """
         Public slot to restart the built in languages.
         """
-        venvName = Preferences.getDebugger("Python3VirtualEnv")
-        interpreter = (
-            ericApp().getObject("VirtualEnvManager").getVirtualenvInterpreter(venvName)
-        )
-        if not interpreter:
-            interpreter = Globals.getPythonExecutable()
+        interpreter = self.__getPythonInterpreter()
 
         # Tweak the processes list to reflect the changed interpreter
         proc, inter = self.processes.pop("Python3", [None, None])

eric ide

mercurial