feat: 添加桌面版应用和心跳监控
新增功能: - src/desktop.py: PyQt6 桌面应用,支持 Droidcam 摄像头 - 实时视频预览 + 绿色扫描框叠加 - 空格键快速拍照识别 - 批量记录管理和 Excel 导出 - heartbeat.py: 服务心跳监控,自动重启 Streamlit - requirements-desktop.txt: 桌面版专用依赖 Web 版优化: - src/app.py: 自定义摄像头组件,扫描框叠加到视频流 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
53
heartbeat.py
Normal file
53
heartbeat.py
Normal file
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env python3
|
||||
"""心跳程序 - 保持服务活跃"""
|
||||
import sys
|
||||
import time
|
||||
import subprocess
|
||||
import requests
|
||||
from datetime import datetime
|
||||
|
||||
# 禁用输出缓冲
|
||||
sys.stdout.reconfigure(line_buffering=True)
|
||||
|
||||
|
||||
def log(msg):
|
||||
print(f"[{datetime.now():%Y-%m-%d %H:%M:%S}] {msg}", flush=True)
|
||||
|
||||
|
||||
def check_streamlit():
|
||||
"""检查 Streamlit 服务"""
|
||||
try:
|
||||
r = requests.get("http://localhost:8501", timeout=5)
|
||||
return r.status_code == 200
|
||||
except:
|
||||
return False
|
||||
|
||||
|
||||
def restart_streamlit():
|
||||
"""重启 Streamlit"""
|
||||
subprocess.run(["pkill", "-f", "streamlit run"], capture_output=True)
|
||||
time.sleep(2)
|
||||
subprocess.Popen(
|
||||
["streamlit", "run", "src/app.py", "--server.port", "8501", "--server.address", "0.0.0.0"],
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
)
|
||||
print(f"[{datetime.now():%H:%M:%S}] Streamlit 已重启")
|
||||
|
||||
|
||||
def main():
|
||||
log("心跳程序启动")
|
||||
|
||||
while True:
|
||||
if not check_streamlit():
|
||||
log("Streamlit 无响应,正在重启...")
|
||||
restart_streamlit()
|
||||
time.sleep(10)
|
||||
else:
|
||||
log("✓ 服务正常")
|
||||
|
||||
time.sleep(60) # 每分钟检查一次
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user