|
@@ -1,5 +1,5 @@
|
|
|
# -*- coding: utf-8 -*-
|
|
|
-import datetime
|
|
|
+from datetime import datetime
|
|
|
from flask import Flask, render_template
|
|
|
from flask_socketio import SocketIO, emit
|
|
|
from scriptBase.comon import *
|
|
@@ -15,9 +15,9 @@ from concurrent.futures import ThreadPoolExecutor
|
|
|
executor = ThreadPoolExecutor(max_workers=1)
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
-socketio = SocketIO(app)
|
|
|
+socketio = SocketIO(app, cors_allowed_origins="*")
|
|
|
event = threading.Event()
|
|
|
-g_status = ''
|
|
|
+g_status_list = []
|
|
|
last_time = 0.0
|
|
|
task_queue = deque()
|
|
|
last_process = ''
|
|
@@ -60,18 +60,33 @@ def send_hint(msg):#数组信息
|
|
|
emit('processing_hint', msg)
|
|
|
|
|
|
def send_status(msg):#软件执行状态
|
|
|
- global g_status
|
|
|
+ global g_status_list
|
|
|
try:
|
|
|
- if msg == '':
|
|
|
- emit('processing_status', g_status)
|
|
|
- return
|
|
|
+ if not msg == "":
|
|
|
+ # 添加新的状态消息和时间到列表
|
|
|
+ timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S') # 获取当前时间
|
|
|
+ status_entry = {'msg': msg, 'time': timestamp} # 存储消息和时间
|
|
|
+ g_status_list.append(status_entry)
|
|
|
+
|
|
|
+ # 如果列表超过 5 条,移除最早的一条
|
|
|
+ if len(g_status_list) > 5:
|
|
|
+ g_status_list.pop(0)
|
|
|
else:
|
|
|
- g_status = msg
|
|
|
+ sendStr = ''
|
|
|
+ for item in g_status_list:
|
|
|
+ sendStr = sendStr + f"{item['time']}-{item['msg']}<br>"
|
|
|
+
|
|
|
+ #print(sendStr)
|
|
|
+ emit('processing_status', sendStr)
|
|
|
+
|
|
|
|
|
|
+
|
|
|
+ # 如果消息是 "结束",发送所有状态并清空列表
|
|
|
if msg == "结束":
|
|
|
+ g_status_list = [] # 清空列表
|
|
|
event.clear()
|
|
|
- emit('processing_status', msg)
|
|
|
- except:
|
|
|
+ except Exception as e:
|
|
|
+ print(f"Error in send_status: {e}")
|
|
|
return
|
|
|
|
|
|
|