[SCM] morituri/master: * morituri/common/task.py: Failed and done can stay unimplemented. If we read stdout or stderr, reschedule immediately to process all output before considering the possibility the program stopped.

js at users.alioth.debian.org js at users.alioth.debian.org
Sun Oct 19 20:09:49 UTC 2014


The following commit has been merged in the master branch:
commit cec7f71502ee8b5a73ef0b8e6a2b346a86469da2
Author: Thomas Vander Stichele <thomas (at) apestaart (dot) org>
Date:   Tue Dec 4 00:13:25 2012 +0000

    	* morituri/common/task.py:
    	  Failed and done can stay unimplemented.
    	  If we read stdout or stderr, reschedule immediately to process
    	  all output before considering the possibility the program stopped.

diff --git a/ChangeLog b/ChangeLog
index 455919c..580302b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2012-12-04  Thomas Vander Stichele  <thomas at apestaart dot org>
 
+	* morituri/common/task.py:
+	  Failed and done can stay unimplemented.
+	  If we read stdout or stderr, reschedule immediately to process
+	  all output before considering the possibility the program stopped.
+
+2012-12-04  Thomas Vander Stichele  <thomas at apestaart dot org>
+
 	* morituri/common/config.py:
 	  Add methods to get/set defeating of audio cache.
 	  Make sure that we set read offset even if section is already there.
diff --git a/morituri/common/task.py b/morituri/common/task.py
index 55afffe..f0591d5 100644
--- a/morituri/common/task.py
+++ b/morituri/common/task.py
@@ -28,6 +28,7 @@ class PopenTask(log.Loggable, task.Task):
     logCategory = 'PopenTask'
     bufsize = 1024
     command = None
+    cwd = None
 
     def start(self, runner):
         task.Task.start(self, runner)
@@ -36,7 +37,7 @@ class PopenTask(log.Loggable, task.Task):
             self._popen = asyncsub.Popen(self.command,
                 bufsize=self.bufsize,
                 stdin=subprocess.PIPE, stdout=subprocess.PIPE,
-                stderr=subprocess.PIPE, close_fds=True)
+                stderr=subprocess.PIPE, close_fds=True, cwd=self.cwd)
         except OSError, e:
             import errno
             if e.errno == errno.ENOENT:
@@ -51,18 +52,30 @@ class PopenTask(log.Loggable, task.Task):
 
     def _read(self, runner):
         try:
+            read = False
+
             ret = self._popen.recv()
 
             if ret:
                 self.log("read from stdout: %s", ret)
                 self.readbytesout(ret)
+                read = True
 
             ret = self._popen.recv_err()
 
             if ret:
                 self.log("read from stderr: %s", ret)
                 self.readbyteserr(ret)
+                read = True
+
+            # if we read anything, we might have more to read, so
+            # reschedule immediately
+            if read and self.runner:
+                self.schedule(0.0, self._read, runner)
+                return
 
+            # if we didn't read anything, give the command more time to
+            # produce output
             if self._popen.poll() is None and self.runner:
                 # not finished yet
                 self.schedule(1.0, self._read, runner)
@@ -115,13 +128,13 @@ class PopenTask(log.Loggable, task.Task):
         """
         Called when the command completed successfully.
         """
-        raise NotImplementedError
+        pass
 
     def failed(self):
         """
         Called when the command failed.
         """
-        raise NotImplementedError
+        pass
 
 
     def commandMissing(self):

-- 
morituri packaging



More information about the pkg-multimedia-commits mailing list