]> git-server-git.apps.pok.os.sepia.ceph.com Git - remoto.git/commitdiff
Loop around stdout and stderr descriptors until they are exhausted
authorAlfredo Deza <alfredo@deza.pe>
Tue, 21 Apr 2015 13:54:28 +0000 (09:54 -0400)
committerAlfredo Deza <alfredo@deza.pe>
Tue, 21 Apr 2015 13:54:28 +0000 (09:54 -0400)
Even though process.poll() may indicate the process is done.

Fixes issue #15

Signed-off-by: Alfredo Deza <alfredo@deza.pe>
remoto/process.py

index f2445a55920127eb69e1eda44323bc53e1012fbc..3dc7d5ee4a19adc9c3f3ca02a4ae38bb1fb4e119 100644 (file)
@@ -37,6 +37,30 @@ def _remote_run(channel, cmd, **kw):
                     sys.stderr.flush()
 
         if process.poll() is not None:
+            # ensure we do not have anything pending in stdout or stderr
+            # unfortunately, we cannot abstract this repetitive loop into its
+            # own function because execnet does not allow for non-global (or
+            # even nested functions). This must be repeated here.
+            while True:
+                for descriptor in reads:
+                    if descriptor == process.stdout.fileno():
+                        read = process.stdout.readline()
+                        if read:
+                            channel.send({'debug': read})
+                            sys.stdout.flush()
+
+                    if descriptor == process.stderr.fileno():
+                        read = process.stderr.readline()
+                        if read:
+                            channel.send({'warning': read})
+                            sys.stderr.flush()
+                # At this point we have gone through all the possible
+                # descriptors and `read` was empty, so we now can break out of
+                # this since all stdout/stderr has been properly flushed to
+                # logging
+                if not read:
+                    break
+
             break
 
     returncode = process.wait()