]> scripts.mit.edu Git - wizard.git/blobdiff - wizard/shell.py
Make logging not retarded. Fix tests.
[wizard.git] / wizard / shell.py
index eb22844f7bf185f1f849df40dc2de9abad98bd3e..66496eca60d07cd15903f30812348211bf53c3c2 100644 (file)
@@ -258,10 +258,20 @@ class ParallelShell(Shell):
         if len(self.running) < self.max: return
         # now, wait for open pids.
         try:
-            pid, status = os.waitpid(-1, 0)
+            self.reap(*os.waitpid(-1, 0))
         except OSError as e:
             if e.errno == errno.ECHILD: return
-            raise e
+            raise
+    def join(self):
+        """Waits for all of our subprocesses to terminate."""
+        try:
+            while True:
+                self.reap(*os.waitpid(-1, 0))
+        except OSError as e:
+            if e.errno == errno.ECHILD: return
+            raise
+    def reap(self, pid, status):
+        """Reaps a process."""
         # ooh, zombie process. reap it
         proc, args, python, on_success, on_error = self.running.pop(pid)
         # XXX: this is slightly dangerous; should actually use
@@ -275,14 +285,7 @@ class ParallelShell(Shell):
             on_error(eclass(proc.returncode, args, stdout, stderr))
             return
         on_success(stdout, stderr)
-    def join(self):
-        """Waits for all of our subprocesses to terminate."""
-        try:
-            while os.waitpid(-1, 0):
-                pass
-        except OSError as e:
-            if e.errno == errno.ECHILD: return
-            raise e
+
 
 class DummyParallelShell(ParallelShell):
     """Same API as :class:`ParallelShell`, but doesn't actually