plotly / plotly/plotly.py

memory leak in Python 3.13 free-threaded build

未关闭
#5,176 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

bug P2 regression
主要语言
Python
星标
18.8k
派生
2.8k
平均合并
16 小时 26 分钟
30 天内合并 PR
21

描述

I spent some time trying to debug a memory leak caused by calling plotly.express.line within a Dash live update callback under a Python 3.13.3t (free-threaded). Setting PYTHON_GIL=0 or PYTHON_GIL=1 appears to make no difference.

By no means have I located the root cause of the issue (not yet anyway), but I've been able to at least narrow it down to at least one problematic line of code in the BaseFigure class

https://github.com/plotly/plotly.py/blob/main/plotly/basedatatypes.py#L581

If I run the example code shown below (which is HIGHLY distilled from the originating Dash app I was trying to debug), the memory footprint seems to steadily climb with each iteration. If I comment out the offending line within BaseFigure (shown above), the memory footprint remains stable

#!/usr/bin/env -S python3 -u

import sys
import time
from plotly.basedatatypes import BaseFigure

gil = sys._is_gil_enabled()
print(f'GIL enabled = {gil}')

while True:
    BaseFigure()
    BaseFigure()
    BaseFigure()
    time.sleep(.01)

For long running applications like the one described earlier, slow and steady memory consumption issues are causing some rather significant issues.

System details

OS: docker://python:3.12-slim-bookworm
Arch: aarch64
Python version: uv python install 3.13.3t
Plotly version: 6.0.1

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先在 Python 3.13.3t 下运行精简的 BaseFigure 循环,并观察其内存占用。检查 plotly/basedatatypes.py 第 581 行附近的代码,然后将该行注释掉并比较行为。完成的标准是确定原因,并确认重复创建 BaseFigure 不再导致内存持续增长。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
performance
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。