使用 Saxonica(saxonche) 和 Python 处理 XML 文件时出现问题

问题描述 投票:0回答:1

我正在使用

saxonche
python 库来执行 Python 中的 XPath3.1 操作。我创建了一个 FastAPI,它只接受 XML 文件名、打开它、处理并返回响应。 它在 Intel MacBook 上的开发过程中运行良好,但在 Amazon m7g.2xlarge 实例 (Debian 12 ARM64) 上的生产中,在处理多个文件时失败并出现以下错误。

Fatal error: StackOverflowError: Enabling the yellow zone of the stack did not make any stack space available. Possible reasons for that: 1) A call from native code to Java code provided the wrong JNI environment or the wrong IsolateThread; 2) Frames of native code filled the stack, and now there is not even enough stack space left to throw a regular StackOverflowError; 3) An internal VM error occurred.

XML 文件大小:5 至 8 MB 生产环境:m7g.2xlarge(AWS) 与 Debian 12 ARM64

问题
saxonche 在同时处理多个文件时是否有限制?
升级服务器上的 Java 是否可以解决此问题?

任何有关故障排除或解决此错误的建议将不胜感激。 谢谢您的帮助!

python saxon saxon-c
1个回答
0
投票

在我使用的 Python Flask 应用程序中

from saxonche import *

saxon_proc = PySaxonProcessor()

@app.teardown_appcontext
def teardown_saxonche_thread(exception):
    if saxon_proc is not None:
        saxon_proc.detach_current_thread

我不知道 FastAPI 是否有类似的方法来确保 detach_current_thread 完成,但请查看其文档是否/如何运行清理例程。

并避免创建多个 PySaxonProcessor。

© www.soinside.com 2019 - 2024. All rights reserved.