memory leak in Python 3.13 free-threaded build
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 18.8k
- Fork
- 2.8k
- Merge medio
- 16h 26m
- PR unite (30g)
- 21
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia eseguendo il ciclo BaseFigure ridotto con Python 3.13.3t e osserva il suo consumo di memoria. Ispeziona plotly/basedatatypes.py intorno alla riga 581, quindi confronta il comportamento con quella riga commentata. Il lavoro è completato quando la causa è stata identificata e si è confermato che la creazione ripetuta di BaseFigure non causa più una crescita costante della memoria.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- performance
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 35/100