优化flask日志报错问题。优化tidevice运行报错问题
This commit is contained in:
6
.idea/workspace.xml
generated
6
.idea/workspace.xml
generated
@@ -6,8 +6,10 @@
|
|||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="eceeff5e-51c1-459c-a911-d21ec090a423" name="Changes" comment="20250904-初步功能已完成">
|
<list default="true" id="eceeff5e-51c1-459c-a911-d21ec090a423" name="Changes" comment="20250904-初步功能已完成">
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/Module/FlaskSubprocessManager.py" beforeDir="false" afterPath="$PROJECT_DIR$/Module/FlaskSubprocessManager.py" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/Module/FlaskService.py" beforeDir="false" afterPath="$PROJECT_DIR$/Module/FlaskService.py" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/Utils/DevDiskImageDeployer.py" beforeDir="false" afterPath="$PROJECT_DIR$/Utils/DevDiskImageDeployer.py" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/build-tidevice.bat" beforeDir="false" afterPath="$PROJECT_DIR$/build-tidevice.bat" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/resources/iproxy/tidevice.exe" beforeDir="false" afterPath="$PROJECT_DIR$/resources/iproxy/tidevice.exe" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/tidevice_entry.py" beforeDir="false" afterPath="$PROJECT_DIR$/tidevice_entry.py" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
|
|||||||
@@ -61,27 +61,66 @@ def start_socket_listener():
|
|||||||
print(f"[INFO] Socket listener started on port {port}, waiting for connections...")
|
print(f"[INFO] Socket listener started on port {port}, waiting for connections...")
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
LogManager.info(f"[INFO] Waiting for a new connection on port {port}...")
|
|
||||||
print(f"[INFO] Waiting for a new connection on port {port}...")
|
|
||||||
conn, addr = s.accept()
|
conn, addr = s.accept()
|
||||||
LogManager.info(f"[INFO] Connection accepted from: {addr}")
|
LogManager.info(f"[INFO] Connection from {addr}")
|
||||||
print(f"[INFO] Connection accepted from: {addr}")
|
except Exception as e:
|
||||||
|
LogManager.error(f"[ERROR] accept 失败: {e}")
|
||||||
|
continue
|
||||||
|
|
||||||
raw_data = conn.recv(1024).decode('utf-8').strip()
|
# 独立线程处理单条连接,避免单客户端异常拖垮监听线程
|
||||||
LogManager.info(f"[INFO] Raw data received: {raw_data}")
|
threading.Thread(target=_handle_conn, args=(conn, addr), daemon=True).start()
|
||||||
print(f"[INFO] Raw data received: {raw_data}")
|
# while True:
|
||||||
|
# try:
|
||||||
data = json.loads(raw_data)
|
# LogManager.info(f"[INFO] Waiting for a new connection on port {port}...")
|
||||||
LogManager.info(f"[INFO] Parsed data: {data}")
|
# print(f"[INFO] Waiting for a new connection on port {port}...")
|
||||||
print(f"[INFO] Parsed data: {data}")
|
# conn, addr = s.accept()
|
||||||
dataQueue.put(data)
|
# LogManager.info(f"[INFO] Connection accepted from: {addr}")
|
||||||
except Exception as conn_error:
|
# print(f"[INFO] Connection accepted from: {addr}")
|
||||||
LogManager.error(f"[ERROR]连接处理失败: {conn_error}")
|
#
|
||||||
print(f"[ERROR]连接处理失败: {conn_error}")
|
# raw_data = conn.recv(1024).decode('utf-8').strip()
|
||||||
|
# LogManager.info(f"[INFO] Raw data received: {raw_data}")
|
||||||
|
# print(f"[INFO] Raw data received: {raw_data}")
|
||||||
|
#
|
||||||
|
# data = json.loads(raw_data)
|
||||||
|
# LogManager.info(f"[INFO] Parsed data: {data}")
|
||||||
|
# print(f"[INFO] Parsed data: {data}")
|
||||||
|
# dataQueue.put(data)
|
||||||
|
# except Exception as conn_error:
|
||||||
|
# LogManager.error(f"[ERROR]连接处理失败: {conn_error}")
|
||||||
|
# print(f"[ERROR]连接处理失败: {conn_error}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LogManager.error(f"[ERROR]Socket服务启动失败: {e}")
|
LogManager.error(f"[ERROR]Socket服务启动失败: {e}")
|
||||||
print(f"[ERROR]Socket服务启动失败: {e}")
|
print(f"[ERROR]Socket服务启动失败: {e}")
|
||||||
|
|
||||||
|
def _handle_conn(conn: socket.socket, addr):
|
||||||
|
try:
|
||||||
|
with conn:
|
||||||
|
# 1. 循环收包直到拿到完整 JSON
|
||||||
|
buffer = ""
|
||||||
|
while True:
|
||||||
|
data = conn.recv(1024)
|
||||||
|
if not data: # 对端关闭
|
||||||
|
break
|
||||||
|
buffer += data.decode('utf-8', errors='ignore')
|
||||||
|
# 2. 尝试切出完整 JSON(简单按行,也可按长度头、分隔符)
|
||||||
|
while True:
|
||||||
|
line, sep, buffer = buffer.partition('\n')
|
||||||
|
if not sep: # 没找到完整行
|
||||||
|
break
|
||||||
|
line = line.strip()
|
||||||
|
if not line: # 空行跳过
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
obj = json.loads(line)
|
||||||
|
except json.JSONDecodeError as e:
|
||||||
|
LogManager.warning(f"[WARN] 非法 JSON 丢弃: {line[:100]} {e}")
|
||||||
|
continue
|
||||||
|
# 3. 收到合法数据,塞进队列
|
||||||
|
dataQueue.put(obj)
|
||||||
|
LogManager.info(f"[INFO] 收到合法消息: {obj}")
|
||||||
|
except Exception as e:
|
||||||
|
LogManager.error(f"[ERROR] 连接处理异常: {e}")
|
||||||
|
|
||||||
|
|
||||||
# 在独立线程中启动Socket服务
|
# 在独立线程中启动Socket服务
|
||||||
listener_thread = threading.Thread(target=start_socket_listener, daemon=True)
|
listener_thread = threading.Thread(target=start_socket_listener, daemon=True)
|
||||||
|
|||||||
Binary file not shown.
@@ -1,3 +1,18 @@
|
|||||||
|
# from tidevice.__main__ import main
|
||||||
|
# if __name__ == '__main__':
|
||||||
|
# main()
|
||||||
|
|
||||||
|
|
||||||
|
# tidevice_entry.py
|
||||||
|
import sys, traceback, os
|
||||||
from tidevice.__main__ import main
|
from tidevice.__main__ import main
|
||||||
if __name__ == '__main__':
|
|
||||||
main()
|
if __name__ == "__main__":
|
||||||
|
try:
|
||||||
|
main()
|
||||||
|
except Exception:
|
||||||
|
# 把 traceback 写到日志文件,但**不输出到控制台**
|
||||||
|
with open(os.path.expanduser("~/tidevice_crash.log"), "a", encoding="utf-8") as f:
|
||||||
|
traceback.print_exc(file=f)
|
||||||
|
# 静默退出,**返回码 1**(父进程只认 returncode)
|
||||||
|
sys.exit(1)
|
||||||
Reference in New Issue
Block a user