Skip to content

Commit dc9dec4

Browse files
committed
move log_stream outside of class
1 parent f9165b1 commit dc9dec4

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

build/tools/command.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ class CommandResult:
5050
)
5151
end_time: Optional[datetime.datetime] = None
5252

53+
54+
async def _process_log_stream(stream, result: CommandResult):
55+
"""Logs the output of a subprocess stream."""
56+
while True:
57+
line_bytes = await stream.readline()
58+
if not line_bytes:
59+
break
60+
line = line_bytes.decode().rstrip()
61+
result.logs += line
62+
logger.info("%s", line)
63+
64+
5365
class SubprocessExecutor:
5466
"""
5567
Manages execution of subprocess commands with reusable environment and logging.
@@ -89,17 +101,8 @@ async def run(self, cmd: str, dry_run: bool = False) -> CommandResult:
89101
env=self.environment,
90102
)
91103

92-
async def log_stream(stream, result: CommandResult):
93-
while True:
94-
line_bytes = await stream.readline()
95-
if not line_bytes:
96-
break
97-
line = line_bytes.decode().rstrip()
98-
result.logs += line
99-
logger.info("%s", line)
100-
101104
await asyncio.gather(
102-
log_stream(process.stdout, result), log_stream(process.stderr, result)
105+
_process_log_stream(process.stdout, result), _process_log_stream(process.stderr, result)
103106
)
104107

105108
result.return_code = await process.wait()

0 commit comments

Comments
 (0)