Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix blocking log #1268

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions gpt_engineer/core/default/disk_execution_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
- FilesDict: For handling collections of files.
"""

import fcntl
import os
import subprocess
import time

Expand All @@ -33,6 +35,17 @@
from gpt_engineer.core.files_dict import FilesDict


# Taken from https://gist.github.com/sebclaeys/1232088
def non_block_read(output):
fd = output.fileno()
fl = fcntl.fcntl(fd, fcntl.F_GETFL)
fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
try:
return output.readline()
except:
return ""


class DiskExecutionEnv(BaseExecutionEnv):
"""
An execution environment that runs code on the local file system and captures
Expand Down Expand Up @@ -88,8 +101,8 @@ def run(self, command: str, timeout: Optional[int] = None) -> Tuple[str, str, in
while p.poll() is None:
assert p.stdout is not None
assert p.stderr is not None
stdout = p.stdout.readline()
stderr = p.stderr.readline()
stdout = non_block_read(p.stdout)
stderr = non_block_read(p.stderr)
if stdout:
print(stdout, end="")
stdout_full += stdout
Expand Down
Loading