Skip to content

Commit 14e3a91

Browse files
Fix: http agent server (#276)
* Fix the agent service being suspended * remove unnecessary codeline * update comments
1 parent e304e5d commit 14e3a91

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

lagent/distributed/http_serve/api_server.py

+16-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import subprocess
44
import sys
55
import time
6+
import threading
67

78
import aiohttp
89
import requests
@@ -77,14 +78,21 @@ def start_server(self):
7778
stderr=subprocess.STDOUT,
7879
text=True)
7980

80-
while True:
81-
output = self.process.stdout.readline()
82-
if not output: # 如果读到 EOF,跳出循环
83-
break
84-
sys.stdout.write(output) # 打印到标准输出
85-
sys.stdout.flush()
86-
if 'Uvicorn running on' in output: # 根据实际输出调整
87-
break
81+
self.service_started = False
82+
83+
def log_output(stream):
84+
if stream is not None:
85+
for line in iter(stream.readline, ''):
86+
print(line, end='')
87+
if 'Uvicorn running on' in line:
88+
self.service_started = True
89+
90+
# Start log output thread
91+
threading.Thread(target=log_output, args=(self.process.stdout,), daemon=True).start()
92+
threading.Thread(target=log_output, args=(self.process.stderr,), daemon=True).start()
93+
94+
# Waiting for the service to start
95+
while not self.service_started:
8896
time.sleep(0.1)
8997

9098
def shutdown(self):

0 commit comments

Comments
 (0)