From 73eb76426b09d521b95f77b0bb3ba5f39d5677e2 Mon Sep 17 00:00:00 2001
From: Pieter Donker <donker@astron.nl>
Date: Wed, 16 Sep 2015 09:56:23 +0000
Subject: [PATCH] Task #8389: check_output() now non-blocking

---
 LCU/PPSTune/ppstune.py                  | 32 ++++++++++++-------------
 MAC/APL/PIC/RSP_Driver/src/Sequencer.cc |  2 +-
 2 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/LCU/PPSTune/ppstune.py b/LCU/PPSTune/ppstune.py
index a2cf22eb4f2..58c3c7506ef 100755
--- a/LCU/PPSTune/ppstune.py
+++ b/LCU/PPSTune/ppstune.py
@@ -188,32 +188,32 @@ def check_output(args, stderr = None, execute = True, timeout_s = None):
                 stdout = subprocess.PIPE,
                 stdin  = subprocess.PIPE,
                 stderr = stderr)
-            stdout = []
-            out = ''
-            while True:
-                out = process.stdout.read(1)
-                if out == '' and process.poll() != None:
-                    break
-                if out != '':
-                    stdout.append(out)
+            
+            proc_ready = True
+            while process.poll() == None:  # while poll() returns None, process is still running.
                 if time.time() - start_date > timeout_s:
+                    proc_ready = False
                     logging.error('timeout after %6.3f s: terminating command %s ',
                                   timeout_s, ' '.join(args))
-                    os.kill(process.pid, signal.SIGTERM)
-                    raise RuntimeError('%s killed with signal %d; output:\n%r' %
-                                       (' '.join(args), signal.SIGTERM,
-                                        ''.join(stdout)))
+                    break
+                time.sleep(1.0)
+            
             logging.debug('process.poll(): %r', process.poll())
             if process.poll() < 0:
                 raise RuntimeError('%s killed with signal %d' %
                                    (' '.join(args), process.poll()))
-            return ''.join(stdout)
+            
+            if proc_ready:
+                return process.communicate()[0]
+            
+            os.kill(process.pid, signal.SIGTERM)
+            raise RuntimeError('%s killed with signal %d; output:\n%r' %
+                              (' '.join(args), signal.SIGTERM,
+                               ''.join(stdout)))
+            return ''
     else:
         return ''
 
-
-
-
 def gmtime_tuple(date_s):
     r'''
     Return the ``date_s`` as a gmtime tuple containing (year, month,
diff --git a/MAC/APL/PIC/RSP_Driver/src/Sequencer.cc b/MAC/APL/PIC/RSP_Driver/src/Sequencer.cc
index 97ab6f66623..58a8880bca2 100644
--- a/MAC/APL/PIC/RSP_Driver/src/Sequencer.cc
+++ b/MAC/APL/PIC/RSP_Driver/src/Sequencer.cc
@@ -38,7 +38,7 @@ namespace LOFAR {
     namespace RSP {
 
 #define STARTUP_WAIT   10
-#define CLOCK_WAIT     4
+#define CLOCK_WAIT     5
 #define TDWRITE_WAIT   1
 #define TDREAD_TIMEOUT 3
 #define RSUCLEAR_WAIT  5
-- 
GitLab