使用上下文管理器修复文件资源泄露
作者: YutShang创建于 2026年9月2日更新于 2026年9月2日
标签bug
Problem Description In the from_json method of the MetricAnnotation and SingleMetricAnnotation classes, the JSON file is read directly using json.load(open(path)), without using the with context manager. After the file is opened, the file handle is not explicitly closed, and the file resources are released by the Python GC garbage collector. In high-frequency batch file reading scenarios, this can cause file handle leaks, which can trigger the Too many open files exception when the number of open files reaches the system limit.
内容来源: vibrantlabsai/ragas