mirror of
https://github.com/Pythagora-io/gpt-pilot.git
synced 2026-01-09 05:07:54 -05:00
Add show_output functionality to start_process
This commit is contained in:
@@ -419,7 +419,7 @@ class Frontend(FileDiffMixin, GitMixin, BaseAgent):
|
||||
await self.kill_app()
|
||||
|
||||
# 1. Start npm run start in the background
|
||||
npm_proc = await self.process_manager.start_process("npm run start &")
|
||||
npm_proc = await self.process_manager.start_process("npm run start &", show_output=False)
|
||||
|
||||
# 2. Wait for the server to start
|
||||
await asyncio.sleep(2)
|
||||
|
||||
@@ -30,6 +30,7 @@ class LocalProcess:
|
||||
stdout: str
|
||||
stderr: str
|
||||
_process: asyncio.subprocess.Process
|
||||
show_output: bool
|
||||
|
||||
def __hash__(self) -> int:
|
||||
return hash(self.id)
|
||||
@@ -41,6 +42,7 @@ class LocalProcess:
|
||||
cwd: str = ".",
|
||||
env: dict[str, str],
|
||||
bg: bool = False,
|
||||
show_output: Optional[bool] = True,
|
||||
) -> "LocalProcess":
|
||||
log.debug(f"Starting process: {cmd} (cwd={cwd})")
|
||||
_process = await asyncio.create_subprocess_shell(
|
||||
@@ -56,13 +58,7 @@ class LocalProcess:
|
||||
_process.stdin.close()
|
||||
|
||||
return LocalProcess(
|
||||
id=uuid4(),
|
||||
cmd=cmd,
|
||||
cwd=cwd,
|
||||
env=env,
|
||||
stdout="",
|
||||
stderr="",
|
||||
_process=_process,
|
||||
id=uuid4(), cmd=cmd, cwd=cwd, env=env, stdout="", stderr="", _process=_process, show_output=show_output
|
||||
)
|
||||
|
||||
async def wait(self, timeout: Optional[float] = None) -> int:
|
||||
@@ -190,7 +186,7 @@ class ProcessManager:
|
||||
|
||||
for process in procs:
|
||||
out, err = await process.read_output()
|
||||
if self.output_handler and (out or err):
|
||||
if process.show_output and self.output_handler and (out or err):
|
||||
await self.output_handler(out, err)
|
||||
|
||||
if not process.is_running:
|
||||
@@ -210,10 +206,11 @@ class ProcessManager:
|
||||
cwd: str = ".",
|
||||
env: Optional[dict[str, str]] = None,
|
||||
bg: bool = True,
|
||||
show_output: Optional[bool] = True,
|
||||
) -> LocalProcess:
|
||||
env = {**self.default_env, **(env or {})}
|
||||
abs_cwd = abspath(join(self.root_dir, cwd))
|
||||
process = await LocalProcess.start(cmd, cwd=abs_cwd, env=env, bg=bg)
|
||||
process = await LocalProcess.start(cmd, cwd=abs_cwd, env=env, bg=bg, show_output=show_output)
|
||||
if bg:
|
||||
self.processes[process.id] = process
|
||||
return process
|
||||
|
||||
Reference in New Issue
Block a user