Skip to content
Merged
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
26 changes: 14 additions & 12 deletions scripts/host_agy_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ def get_last_conversation_id():
pass
return None

def read_file_sync(path):
"""Synchronously read and return content from a file, returning empty string on error."""
try:
with open(path, "r", encoding="utf-8", errors="replace") as f:
return f.read().strip()
except Exception:
return ""

class AgyDaemonHandler(BaseHTTPRequestHandler):
"""HTTP request handler for agy execution requests."""
def do_POST(self):
Expand Down Expand Up @@ -180,18 +188,12 @@ async def run():
except Exception:
returncode = -1

# Read output from the temporary files
try:
with open(stdout_path, "r", encoding="utf-8", errors="replace") as f:
stdout = f.read().strip()
except Exception:
stdout = ""

try:
with open(stderr_path, "r", encoding="utf-8", errors="replace") as f:
stderr = f.read().strip()
except Exception:
stderr = ""
# Read output from the temporary files without blocking the event loop concurrently
loop_ref = asyncio.get_running_loop()
stdout, stderr = await asyncio.gather(
loop_ref.run_in_executor(None, read_file_sync, stdout_path),
loop_ref.run_in_executor(None, read_file_sync, stderr_path),
)

Comment thread
sourcery-ai[bot] marked this conversation as resolved.
# Clean up temporary files
for path in [stdout_path, stderr_path]:
Expand Down