|
16 | 16 | limitations under the License. |
17 | 17 | """ |
18 | 18 |
|
19 | | -import io |
20 | | -import platform |
21 | 19 | import os |
22 | 20 | import sys |
23 | | -import time |
24 | | -import socket |
25 | 21 | import logging |
26 | 22 | from functools import partial |
27 | | -from subprocess import Popen, PIPE, STDOUT, TimeoutExpired |
| 23 | +from subprocess import Popen, PIPE, STDOUT |
| 24 | +from threading import Thread |
| 25 | +from queue import Queue, Empty |
| 26 | +ON_POSIX = 'posix' in sys.builtin_module_names |
| 27 | + |
28 | 28 |
|
29 | 29 | class SimulatorError(Exception): |
30 | 30 | """ |
@@ -128,20 +128,33 @@ def remove_gcda(rootdir="."): |
128 | 128 | if file.endswith(".gcda"): |
129 | 129 | os.remove(os.path.join(root, file)) |
130 | 130 |
|
131 | | -def launch_FVP_IRIS(model_exec, config_file='', lines_out=6): |
| 131 | +def enqueue_output(out, queue): |
| 132 | + for line in iter(out.readline, b''): |
| 133 | + queue.put(line) |
| 134 | + out.close() |
| 135 | + |
| 136 | +def launch_FVP_IRIS(model_exec, config_file=''): |
132 | 137 | """Launch FVP with IRIS Server listening""" |
133 | 138 | cmd_line = [model_exec, '-I', '-p'] |
134 | 139 | if config_file: |
135 | 140 | cmd_line.extend(['-f' , config_file]) |
136 | | - fm_proc = Popen(cmd_line,stdout=PIPE,stderr=STDOUT) |
| 141 | + fm_proc = Popen(cmd_line,stdout=PIPE,stderr=STDOUT, close_fds=ON_POSIX) |
| 142 | + out_q = Queue() |
| 143 | + reader_t = Thread(target=enqueue_output, args=(fm_proc.stdout, out_q)) |
| 144 | + reader_t.daemon = True |
| 145 | + reader_t.start() |
137 | 146 |
|
138 | 147 | stdout='' |
139 | 148 | port = 0 |
140 | | - |
141 | | - for num in range(lines_out): |
142 | | - line = fm_proc.stdout.readline().decode() |
143 | | - if line.startswith("Iris server started listening to port"): |
144 | | - port = int(line[-5:]) |
145 | | - stdout += line |
| 149 | + end = False |
| 150 | + |
| 151 | + while not end: |
| 152 | + try: line = out_q.get(timeout=1).decode().strip() |
| 153 | + except Empty: |
| 154 | + end = True |
| 155 | + else: |
| 156 | + if line.startswith("Iris server started listening to port"): |
| 157 | + port = int(line[-5:]) |
| 158 | + stdout = stdout + line + "\n" |
146 | 159 |
|
147 | 160 | return (fm_proc, port, stdout) |
0 commit comments