修复子进程日志输出

This commit is contained in:
zw
2025-08-01 14:52:18 +08:00
parent 3c60d3c7d2
commit 1269cf0573
2 changed files with 14 additions and 12 deletions

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@@ -52,20 +52,16 @@ class FlaskSubprocessManager:
print(f"Flask子进程启动 (PID: {self.process.pid}, 通信端口: {self.comm_port})")
# 将日志通过主进程输出
def print_output():
def print_output(stream, stream_name):
while True:
output = self.process.stdout.readline()
if not output:
line = stream.readline()
if not line:
break
print(output.strip())
print(f"{stream_name}: {line.strip()}")
while True:
error = self.process.stderr.readline()
if not error:
break
print(f"Error: {error.strip()}")
threading.Thread(target=print_output, daemon=True).start()
# 启动两个线程分别处理 stdout 和 stderr
threading.Thread(target=print_output, args=(self.process.stdout, "STDOUT"), daemon=True).start()
threading.Thread(target=print_output, args=(self.process.stderr, "STDERR"), daemon=True).start()
def send(self, data: Union[str, Dict, List]) -> bool:
"""通过Socket发送数据"""