mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-11 15:15:18 +02:00
Merge branch 'feature-terminal-async' into 'mgx_ops'
Feature terminal async See merge request pub/MetaGPT!221
This commit is contained in:
commit
519ef956f9
1 changed files with 5 additions and 4 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import asyncio
|
||||
from asyncio import Queue
|
||||
from asyncio.subprocess import PIPE
|
||||
from asyncio.subprocess import PIPE, STDOUT
|
||||
from typing import Optional
|
||||
|
||||
from metagpt.const import DEFAULT_WORKSPACE_ROOT, SWE_SETUP_PATH
|
||||
|
|
@ -28,7 +28,7 @@ class Terminal:
|
|||
async def _start_process(self):
|
||||
# Start a persistent shell process
|
||||
self.process = await asyncio.create_subprocess_exec(
|
||||
*self.shell_command, stdin=PIPE, stdout=PIPE, stderr=PIPE, executable="/bin/bash"
|
||||
*self.shell_command, stdin=PIPE, stdout=PIPE, stderr=STDOUT, executable="/bin/bash"
|
||||
)
|
||||
await self._check_state()
|
||||
|
||||
|
|
@ -115,6 +115,7 @@ class Terminal:
|
|||
# '\r' is changed to '\n', resulting in excessive output.
|
||||
tmp = b""
|
||||
while True:
|
||||
self.process.communicate()
|
||||
output = tmp + await self.process.stdout.read(1)
|
||||
*lines, tmp = output.splitlines(True)
|
||||
for line in lines:
|
||||
|
|
@ -123,12 +124,12 @@ class Terminal:
|
|||
if ix >= 0:
|
||||
line = line[0:ix]
|
||||
if line:
|
||||
observer.report(line, "output")
|
||||
await observer.async_report(line, "output")
|
||||
# report stdout in real-time
|
||||
cmd_output.append(line)
|
||||
return "".join(cmd_output)
|
||||
# log stdout in real-time
|
||||
observer.report(line, "output")
|
||||
await observer.async_report(line, "output")
|
||||
cmd_output.append(line)
|
||||
if daemon:
|
||||
await self.stdout_queue.put(line)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue