46 lines
1.4 KiB
Python
46 lines
1.4 KiB
Python
# 主程序入口
|
|
import os
|
|
import signal
|
|
import threading
|
|
import torch
|
|
from log import logger
|
|
|
|
import global_data as gd
|
|
from server import socketio, app
|
|
|
|
gd._init()
|
|
|
|
gd.set_value('detection_thread', None)
|
|
gd.set_value('detection_active', False)
|
|
gd.set_value('stop_event', threading.Event())
|
|
gd.set_value('mqtt_client', None)
|
|
gd.set_value('latest_drone_data', None)
|
|
gd.set_value('mqtt_data_lock', threading.Lock())
|
|
|
|
if __name__ == '__main__':
|
|
logger.info("启动优化版YOLOv8服务")
|
|
# 优化2: 使用最新版本YOLO和PyTorch特性
|
|
logger.info(f"PyTorch版本: {torch.__version__}, CUDA可用: {torch.cuda.is_available()}")
|
|
# 退出服务
|
|
def graceful_exit(signum, frame):
|
|
logger.info("收到退出信号,停止服务...")
|
|
detection_active = gd.get_value('detection_active')
|
|
detection_thread = gd.get_value('detection_thread')
|
|
if detection_active and detection_thread:
|
|
detection_thread.stop()
|
|
detection_thread.join(5.0)
|
|
logger.info("服务已退出")
|
|
os._exit(0)
|
|
|
|
|
|
signal.signal(signal.SIGINT, graceful_exit)
|
|
signal.signal(signal.SIGTERM, graceful_exit)
|
|
|
|
# 启动服务 - 禁用开发服务器调试
|
|
socketio.run(app,
|
|
host='0.0.0.0',
|
|
port=9309,
|
|
debug=True, # 禁用调试模式
|
|
use_reloader=False,
|
|
allow_unsafe_werkzeug=True)
|