309 |
310 |
310 def ReportOutput(self, text): |
311 def ReportOutput(self, text): |
311 elapsed = "%.3fs: "%(timesec() - self.starttime) |
312 elapsed = "%.3fs: "%(timesec() - self.starttime) |
312 self.report.write("<pre>" + elapsed + text + "</pre>") |
313 self.report.write("<pre>" + elapsed + text + "</pre>") |
313 |
314 |
|
315 |
|
316 class AuxiliaryProcess: |
|
317 def __init__(self, beremiz_app, command): |
|
318 self.app = beremiz_app |
|
319 self.app.ReportText("Launching process " + repr(command)) |
|
320 self.proc = subprocess.Popen(command, stdout=subprocess.PIPE, bufsize=0) |
|
321 self.app.ReportText("Launched process " + repr(command) + " PID: " + str(self.proc.pid)) |
|
322 if self.proc is not None: |
|
323 self.thread = Thread(target = self._waitStdoutProc).start() |
|
324 |
|
325 def _waitStdoutProc(self): |
|
326 while True: |
|
327 a = self.proc.stdout.readline() |
|
328 if len(a) == 0 or a is None: |
|
329 break |
|
330 a = "aux: "+a |
|
331 sys.stdout.write(a) |
|
332 self.ReportOutput(a) |
|
333 self.ReportOutput("AuxStdoutFinish") |
|
334 |
|
335 def close(self): |
|
336 if self.proc is not None: |
|
337 proc = self.proc |
|
338 self.proc = None |
|
339 # self.proc.stdout.close() |
|
340 self.app.ReportText("Kill process PID: " + str(proc.pid)) |
|
341 try: |
|
342 os.kill(proc.pid, signal.SIGTERM) |
|
343 except OSError: |
|
344 pass |
|
345 proc.wait() |
|
346 # self.thread.join() |
|
347 |
|
348 def __del__(self): |
|
349 self.close() |
314 |
350 |
315 def run_test(func, *args, **kwargs): |
351 def run_test(func, *args, **kwargs): |
316 app = BeremizApp(*args, **kwargs) |
352 app = BeremizApp(*args, **kwargs) |
317 try: |
353 try: |
318 success = func(app) |
354 success = func(app) |