`tracemalloc` aborts when run from threads in no-gil
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 36k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
Crash report
What happened?
It's possible to get two different aborts from failed assertions, only with PYTHON_GIL=0, using the code below:
from threading import Thread
import _tracemalloc
alive = [
Thread(target=_tracemalloc.start, args=(
(memoryview(bytearray(b"abc\xe9\xff")),))),
Thread(target=_tracemalloc.start, args=()),
Thread(target=_tracemalloc.get_traceback_limit, args=()),
Thread(target=_tracemalloc.start, args=()),
Thread(target=_tracemalloc.stop, args=()),
Thread(target=_tracemalloc.reset_peak, args=()),
Thread(target=_tracemalloc.get_tracemalloc_memory, args=())
]
for obj in alive:
print('START', obj)
try:
obj.start()
except Exception:
pass
The errors are:
python: Python/tracemalloc.c:445: tracemalloc_remove_trace: Assertion `tracemalloc_config.tracing' failed.
Aborted
And:
python: Python/tracemalloc.c:469: tracemalloc_add_trace: Assertion `tracemalloc_config.tracing' failed.
Aborted
Found with fusil by @vstinner.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
Python 3.14.0a1+ experimental free-threading build (heads/main:d467d9246c, Nov 1 2024, 09:05:56) [GCC 11.4.0]
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece reproduzindo o exemplo fornecido com threads usando um build experimental de free-threading e PYTHON_GIL=0. Inspecione Python/tracemalloc.c em torno de tracemalloc_remove_trace e tracemalloc_add_trace e, em seguida, verifique se o exemplo não aborta mais quando operações de tracemalloc são usadas concorrentemente.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- devtools
- Tipo de issue
- Bug
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Status de atividade
- Pouca atividade
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 45/100