Skip to content

Commit

Permalink
Fix: http agent server (#276)
Browse files Browse the repository at this point in the history
* Fix the agent service being suspended

* remove unnecessary codeline

* update comments
  • Loading branch information
liujiangning30 authored Nov 21, 2024
1 parent e304e5d commit 14e3a91
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions lagent/distributed/http_serve/api_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import subprocess
import sys
import time
import threading

import aiohttp
import requests
Expand Down Expand Up @@ -77,14 +78,21 @@ def start_server(self):
stderr=subprocess.STDOUT,
text=True)

while True:
output = self.process.stdout.readline()
if not output: # 如果读到 EOF,跳出循环
break
sys.stdout.write(output) # 打印到标准输出
sys.stdout.flush()
if 'Uvicorn running on' in output: # 根据实际输出调整
break
self.service_started = False

def log_output(stream):
if stream is not None:
for line in iter(stream.readline, ''):
print(line, end='')
if 'Uvicorn running on' in line:
self.service_started = True

# Start log output thread
threading.Thread(target=log_output, args=(self.process.stdout,), daemon=True).start()
threading.Thread(target=log_output, args=(self.process.stderr,), daemon=True).start()

# Waiting for the service to start
while not self.service_started:
time.sleep(0.1)

def shutdown(self):
Expand Down

0 comments on commit 14e3a91

Please sign in to comment.