Commits

Arne Babenhauserheide  committed e4ae22a

no longer spout process output onto the starting terminal and track all processes explicitely while they are running.

  • Participants
  • Parent commits 1f1dc0b

Comments (0)

Files changed (1)

 
 # First the basic python stuff
 # for starting programs
-from subprocess import Popen
+import subprocess
 
 # basics, currently only for prefix
 import sys
 
     def openShortcutConfig(self):
         """Open the Keyboard Shortcut config dialog"""
-        Popen(["kcmshell4", "keys"])
+        self.parent().processes.add(
+            subprocess.Popen(["kcmshell4", "keys"], stdout=subprocess.PIPE, stderr=subprocess.PIPE))
 
     def openGesturesConfig(self):
         """Open the Keyboard Shortcut config dialog"""
-        Popen(["kcmshell4", "khotkeys"])
+        self.parent().processes.add(
+            subprocess.Popen(["kcmshell4", "khotkeys"], stdout=subprocess.PIPE, stderr=subprocess.PIPE))
 
     def openFlattrUrl(self):
         """Open the flattr Url for the pyrad."""
         # print self.showAction.shapeGesture().toString()
         self.showAction.connect(self.showAction, SIGNAL("triggered(Qt::MouseButtons, Qt::KeyboardModifiers)"), self.showByShortcut)
 
+        # track subprocesses. Communicate with them from time to time
+        # and kill the dead ones.
+        self.processes = set()
+
         # Setup the circle - TODO: Call it via KUniqueApplication.newInstance
         #self.setup()
 
         # and the circle stays visible.
         if label.action is not None:
             try:
-                Popen(split_action(label.action))
+                self.processes.add(
+                    subprocess.Popen(split_action(label.action), 
+                                     bufsize=-1, # -1 == OS gives the bufsize
+                                     stdout=subprocess.PIPE, 
+                                     stderr=subprocess.STDOUT))
+                # if it works, check all other processes
+                self.checkProcesses()
                 return True
             except:
                 return None
 
-
+    def checkProcesses(self):
+        """Check all subprocesses, if they are still active and throw
+        away their output in that case."""
+        for p in self.processes.copy():
+            # check if the process is still alive (==no return value)
+            if p.poll() is not None:
+                self.processes.remove(p)
 
     def isInside(self, point, thing):
         """Check, if the point is inside the thing."""