[CI]] Tee server logs to both file and stdout/stderr using PIPE (#11185)
This commit is contained in:
@@ -9,6 +9,7 @@ import os
|
|||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import sys
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
import unittest
|
import unittest
|
||||||
@@ -566,11 +567,30 @@ def popen_launch_server(
|
|||||||
if return_stdout_stderr:
|
if return_stdout_stderr:
|
||||||
process = subprocess.Popen(
|
process = subprocess.Popen(
|
||||||
command,
|
command,
|
||||||
stdout=return_stdout_stderr[0],
|
stdout=subprocess.PIPE,
|
||||||
stderr=return_stdout_stderr[1],
|
stderr=subprocess.PIPE,
|
||||||
env=env,
|
env=env,
|
||||||
text=True,
|
text=True,
|
||||||
|
bufsize=1,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _dump(src, sinks):
|
||||||
|
for line in iter(src.readline, ""):
|
||||||
|
for sink in sinks:
|
||||||
|
sink.write(line)
|
||||||
|
sink.flush()
|
||||||
|
src.close()
|
||||||
|
|
||||||
|
threading.Thread(
|
||||||
|
target=_dump,
|
||||||
|
args=(process.stdout, [return_stdout_stderr[0], sys.stdout]),
|
||||||
|
daemon=True,
|
||||||
|
).start()
|
||||||
|
threading.Thread(
|
||||||
|
target=_dump,
|
||||||
|
args=(process.stderr, [return_stdout_stderr[1], sys.stderr]),
|
||||||
|
daemon=True,
|
||||||
|
).start()
|
||||||
else:
|
else:
|
||||||
process = subprocess.Popen(command, stdout=None, stderr=None, env=env)
|
process = subprocess.Popen(command, stdout=None, stderr=None, env=env)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user