write_to_textfile: tmp file is left behind if generator code fails
还没有人认领这个 Issue。
评估
调研方向
从 prometheus_client/exposition.py 中 write_to_textfile 的实现开始,查看第 202-203 行附近的位置;在创建临时文件期间会运行 generate_latest(registry)。跟踪 collector 代码引发异常时的失败路径,并验证最终行为不会留下临时文件,同时保留原子重命名流程。
由索引模型根据 Issue 内容生成。
描述
In the write_to_textfile function, the code to run the collector registry is in the temp file creation block: https://github.com/prometheus/client_python/blob/master/prometheus_client/exposition.py#L202-L203
In my case, I had an error in my collector code (run by generate_latest(registry)). This resulted in many tmp files left over from the errors.
I'm wondering if it would be preferable to run the code before the temp file block, e.g.:
tmppath = '%s.%s.%s' % (path, os.getpid(), threading.current_thread().ident)
out = generate_latest(registry)
with open(tmppath, 'wb') as f:
f.write(out)
# rename(2) is atomic.
os.rename(tmppath, path)
Unless leaving temp files behind is the desired/intended behavior.
- 主要语言
- Python
- 星标
- 4.4k
- 派生
- 876
- 平均合并
- 8 天 4 小时
- 30 天内合并 PR
- 1
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
prometheus/client_python 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 70/100
prometheus/client_python#1177 · 1 条评论 ·
-
难度 4/5 3-5 天 新手友好度 45/100
prometheus/client_python#1210 ·
-
难度 2/5 1-3 小时 新手友好度 58/100
prometheus/client_python#1199 · 1 个 reaction ·
-
难度 5/5 一周以上 新手友好度 35/100
prometheus/client_python#1176 ·
-
难度 1/5 1-3 小时 新手友好度 52/100
prometheus/client_python#1126 · 2 条评论 ·
查看 prometheus/client_python 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 75/100
stephrobert/dsoxlab#238 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 2/5 1-3 小时 新手友好度 75/100
sublimehq/package_control#1780 ·
-
难度 2/5 1-3 小时 新手友好度 65/100
-
难度 2/5 1-3 小时 新手友好度 70/100
nwg-piotr/nwg-displays#145 ·