From d077918c4e54f27a9f81cb87c67f842db8a270fb Mon Sep 17 00:00:00 2001 From: SZCJW <792430652@qq.com> Date: Sun, 8 Mar 2026 20:36:37 +0800 Subject: [PATCH] x --- src/services/verification_service.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/services/verification_service.py b/src/services/verification_service.py index 02975b9..1c80064 100644 --- a/src/services/verification_service.py +++ b/src/services/verification_service.py @@ -4,6 +4,7 @@ """ import asyncio import json +import os import subprocess import sys from pathlib import Path @@ -80,8 +81,8 @@ class GeometryVerificationService: try: result = subprocess.run(['which', cmd_name], capture_output=True, text=True) if result.returncode == 0 and result.stdout.strip(): - # 使用绝对路径,添加 -c 参数使用命令行模式(无图形界面) - cmd = [cmd_name, '-c', str(self.verification_script), str(Path(stp_path_str).absolute())] + # FreeCAD 1.0 直接执行脚本,不需要 -c 参数 + cmd = [cmd_name, str(self.verification_script), str(Path(stp_path_str).absolute())] logger.info(f"找到 FreeCAD 命令: {cmd_name}") break except: @@ -91,8 +92,8 @@ class GeometryVerificationService: if not cmd: for cmd_path in ['/usr/local/bin/freecad', '/usr/bin/freecad', '/usr/local/bin/freecadcmd', '/usr/bin/freecadcmd', '/snap/bin/freecad.cmd']: if Path(cmd_path).exists(): - # 添加 -c 参数使用命令行模式(无图形界面) - cmd = [cmd_path, '-c', str(self.verification_script), str(Path(stp_path_str).absolute())] + # FreeCAD 1.0 直接执行脚本,不需要 -c 参数 + cmd = [cmd_path, str(self.verification_script), str(Path(stp_path_str).absolute())] logger.info(f"找到 FreeCAD 命令路径: {cmd_path}") break @@ -132,12 +133,18 @@ class GeometryVerificationService: stp_abs_path = Path(stp_path_str).absolute() stp_dir = stp_abs_path.parent + # 设置环境变量禁用图形界面 + env = os.environ.copy() + env['QT_QPA_PLATFORM'] = 'offscreen' + env['DISPLAY'] = '' + # 异步运行子进程 process = await asyncio.create_subprocess_exec( *cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE, - cwd=str(stp_dir) # 在 STP 文件所在目录运行 + cwd=str(stp_dir), # 在 STP 文件所在目录运行 + env=env ) # 增加超时时间到 300 秒(5分钟)