x
This commit is contained in:
@@ -19,13 +19,14 @@ logger = get_logger(__name__)
|
||||
class GeometryVerificationService:
|
||||
"""几何验证服务"""
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, timeout: int = 60):
|
||||
# 验证脚本在项目根目录的 scripts 文件夹下
|
||||
# __file__ = /path/to/project/src/services/verification_service.py
|
||||
# parent = /path/to/project/src/services
|
||||
# parent.parent = /path/to/project/src
|
||||
# parent.parent.parent = /path/to/project (正确)
|
||||
self.verification_script = Path(__file__).parent.parent.parent / "scripts" / "verify_stp.py"
|
||||
self.timeout = timeout # 超时时间(秒),默认60秒
|
||||
|
||||
async def verify_stp_file(self, stp_path: str) -> Dict[str, Any]:
|
||||
"""
|
||||
@@ -142,19 +143,19 @@ class GeometryVerificationService:
|
||||
env=env
|
||||
)
|
||||
|
||||
# 30秒超时
|
||||
# 使用配置的超时时间
|
||||
try:
|
||||
stdout, stderr = await asyncio.wait_for(
|
||||
process.communicate(),
|
||||
timeout=30.0
|
||||
timeout=self.timeout
|
||||
)
|
||||
except asyncio.TimeoutError:
|
||||
logger.error("验证脚本执行超时(30秒)")
|
||||
logger.error(f"验证脚本执行超时({self.timeout}秒)")
|
||||
process.kill()
|
||||
await process.wait()
|
||||
return {
|
||||
"status": "error",
|
||||
"error": "验证脚本执行超时(30秒)",
|
||||
"error": f"验证脚本执行超时({self.timeout}秒)",
|
||||
"timestamp": datetime.now().isoformat()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user