dlxj commited on
Commit ·
08196b6
1
Parent(s): f9cdae0
优化日志输出
Browse files
app.py
CHANGED
|
@@ -32,6 +32,7 @@ initQ = False
|
|
| 32 |
|
| 33 |
def run_sakurallm():
|
| 34 |
import subprocess
|
|
|
|
| 35 |
|
| 36 |
def run_command(command):
|
| 37 |
process = subprocess.Popen(
|
|
@@ -43,17 +44,22 @@ def run_sakurallm():
|
|
| 43 |
universal_newlines=True # 兼容不同平台上的换行符
|
| 44 |
)
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
| 49 |
|
| 50 |
-
#
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
-
|
| 57 |
|
| 58 |
# command = ["ping", "-c", "4", "qq.com"]
|
| 59 |
command = [
|
|
@@ -78,8 +84,8 @@ def run_sakurallm():
|
|
| 78 |
'--port',
|
| 79 |
'8080'
|
| 80 |
]
|
| 81 |
-
|
| 82 |
-
|
| 83 |
run_command(command)
|
| 84 |
|
| 85 |
# if returncode != 0:
|
|
|
|
| 32 |
|
| 33 |
def run_sakurallm():
|
| 34 |
import subprocess
|
| 35 |
+
import threading
|
| 36 |
|
| 37 |
def run_command(command):
|
| 38 |
process = subprocess.Popen(
|
|
|
|
| 44 |
universal_newlines=True # 兼容不同平台上的换行符
|
| 45 |
)
|
| 46 |
|
| 47 |
+
def log_stream(stream, prefix):
|
| 48 |
+
for line in iter(stream.readline, ""):
|
| 49 |
+
print(f"{prefix}{line}", end="")
|
| 50 |
+
stream.close()
|
| 51 |
|
| 52 |
+
# 使用线程实时打印 stdout 和 stderr,避免阻塞主线程且防止缓冲区填满
|
| 53 |
+
t_stdout = threading.Thread(target=log_stream, args=(process.stdout, "[LLAMA] "))
|
| 54 |
+
t_stderr = threading.Thread(target=log_stream, args=(process.stderr, "[LLAMA_ERR] "))
|
| 55 |
+
|
| 56 |
+
t_stdout.daemon = True
|
| 57 |
+
t_stderr.daemon = True
|
| 58 |
+
|
| 59 |
+
t_stdout.start()
|
| 60 |
+
t_stderr.start()
|
| 61 |
|
| 62 |
+
return process
|
| 63 |
|
| 64 |
# command = ["ping", "-c", "4", "qq.com"]
|
| 65 |
command = [
|
|
|
|
| 84 |
'--port',
|
| 85 |
'8080'
|
| 86 |
]
|
| 87 |
+
|
| 88 |
+
print("Starting SakuraLLM server...")
|
| 89 |
run_command(command)
|
| 90 |
|
| 91 |
# if returncode != 0:
|