优化丢设备问题
This commit is contained in:
@@ -87,13 +87,12 @@ def start_socket_listener():
|
||||
listener_thread = threading.Thread(target=start_socket_listener, daemon=True)
|
||||
listener_thread.start()
|
||||
|
||||
|
||||
# 获取设备列表
|
||||
@app.route('/deviceList', methods=['GET'])
|
||||
def deviceList():
|
||||
try:
|
||||
with listLock: # 1. 加锁
|
||||
# 先一次性把队列全部消费完
|
||||
with listLock:
|
||||
# 1. 一次性消费完队列
|
||||
while not dataQueue.empty():
|
||||
obj = dataQueue.get()
|
||||
if obj["type"] == 1:
|
||||
@@ -106,7 +105,11 @@ def deviceList():
|
||||
d.get("screenPort") == obj.get("screenPort"):
|
||||
listData.pop(i)
|
||||
break # 同一端口同一设备只删一次
|
||||
return ResultData(data=listData.copy()).toJson() # 2. 返回副本
|
||||
|
||||
# 2. 兜底:只保留 type == 1 的在线设备
|
||||
listData[:] = [d for d in listData if d.get('type') == 1]
|
||||
|
||||
return ResultData(data=listData.copy()).toJson()
|
||||
except Exception as e:
|
||||
LogManager.error("获取设备列表失败:", e)
|
||||
return ResultData(data=[]).toJson()
|
||||
|
||||
Reference in New Issue
Block a user