Tests: IDE: add stdout monitoring capabilities to auxiliary process wxPython4
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Tue, 15 Nov 2022 14:03:04 +0100
branchwxPython4
changeset 3675 d331eb981b44
parent 3674 d10a7907fb43
child 3676 2f79540660f6
Tests: IDE: add stdout monitoring capabilities to auxiliary process
tests/ide_tests/sikuliberemiz.py
--- a/tests/ide_tests/sikuliberemiz.py	Fri Nov 11 16:07:38 2022 +0100
+++ b/tests/ide_tests/sikuliberemiz.py	Tue Nov 15 14:03:04 2022 +0100
@@ -120,7 +120,6 @@
             a = self.proc.stdout.readline()
             if len(a) == 0 or a is None: 
                 break
-            sys.stdout.write(a)
             self.ReportOutput(a)
             self.event.set()
             if self.pattern is not None and a.find(self.pattern) >= 0:
@@ -172,7 +171,6 @@
         found = 0
         self.pattern = pattern
         end_time = timesec() + timeout
-        self.event.clear()
         while True:
             remain = end_time - timesec()
             if remain <= 0 :
@@ -319,27 +317,17 @@
 
     def ReportOutput(self, text):
         elapsed = "%.3fs: "%(timesec() - self.starttime)
+        sys.stdout.write(elapsed + text)
         self.report.write("<pre>" + elapsed + text + "</pre>")
 
 
-class AuxiliaryProcess:
+class AuxiliaryProcess(stdoutIdleObserver):
     def __init__(self, beremiz_app, command):
         self.app = beremiz_app
         self.app.ReportText("Launching process " + repr(command))
         self.proc = subprocess.Popen(command, stdout=subprocess.PIPE, bufsize=0)
         self.app.ReportText("Launched process " + repr(command) + " PID: " + str(self.proc.pid))
-        if self.proc is not None:
-            self.thread = Thread(target = self._waitStdoutProc).start()
-
-    def _waitStdoutProc(self):
-        while True:
-            a = self.proc.stdout.readline()
-            if len(a) == 0 or a is None: 
-                break
-            a = "aux: "+a
-            sys.stdout.write(a)
-            self.ReportOutput(a)
-        self.ReportOutput("AuxStdoutFinish")
+        stdoutIdleObserver.__init__(self)
 
     def close(self):
         if self.proc is not None:
@@ -354,6 +342,12 @@
             proc.wait()
             # self.thread.join()
 
+    def ReportOutput(self, text):
+        self.app.ReportOutput("Aux: "+text)
+
+    def ReportScreenShot(self, msg):
+        self.app.ReportOutput("Aux: "+msg)
+
     def __del__(self):
         self.close()
 
@@ -367,7 +361,6 @@
         # and catch exception cleanly anyhow
         e_type, e_value, e_traceback = sys.exc_info()
         err_msg = "\n".join(traceback.format_exception(e_type, e_value, e_traceback))
-        sys.stdout.write(err_msg)
         app.ReportOutput(err_msg)
         success = False