Broken circular import between `threading` and `_threading_local`
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 30/100
Línea de trabajo
Lee Lib/threading.py y Lib/_threading_local.py en los puntos de importación y creación de objetos referenciados. Reproduce el fallo eliminando _thread._local antes de importar threading; después, revisa el issue relacionado #141460 y el PR enlazado gh-157042. Se considera terminado cuando se resuelva la importación circular y el comportamiento de fallback demostrado quede cubierto por pruebas de regresión.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Bug report
Bug description:
The threading module defines local as follows:
But _threading_local also uses threading as follows:
This was fine at first, since threading never used thread-local data (the import was near the end). However, this changed in gh-114424:
The _threading_local.local object depends on threading.current_thread(), and this dependency occurs when the object is created:
https://github.com/python/cpython/blob/ee521e8ac19ad012ebc4e1b3e71b369988a9b9f8/Lib/_threading_local.py#L93-L96
https://github.com/python/cpython/blob/ee521e8ac19ad012ebc4e1b3e71b369988a9b9f8/Lib/_threading_local.py#L42-L46
The object is created (and local is imported) before current_thread() is defined. As a result, there is the broken circular import, which can be reproduced as follows:
>>> import _thread
>>> del _thread._local
>>> import threading
Traceback (most recent call last):
File "/home/user/.local/share/mise/installs/python/3.14.7/lib/python3.14/threading.py", line 67, in <module>
from _thread import _local as local
ImportError: cannot import name '_local' from '_thread' (unknown location)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<python-input-2>", line 1, in <module>
import threading
File "/home/user/.local/share/mise/installs/python/3.14.7/lib/python3.14/threading.py", line 69, in <module>
from _threading_local import local
File "/home/user/.local/share/mise/installs/python/3.14.7/lib/python3.14/_threading_local.py", line 120, in <module>
from threading import current_thread, RLock
ImportError: cannot import name 'current_thread' from partially initialized module 'threading' (most likely due to a circular import) (/home/user/.local/share/mise/installs/python/3.14.7/lib/python3.14/threading.py)
Since the issue has not been reported before, this raises a legitimate question: is the fallback still relevant?
Related: #141460.
CPython versions tested on:
3.13, 3.14
Operating systems tested on:
Linux
Linked PRs
- gh-157042
- Lenguaje dominante
- Python
- Estrellas
- 77.2k
- Forks
- 36k
- Merge medio
- 1 d 9 h
- PR fusionados (30 d)
- 558
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de python/cpython
-
docs pending
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
stdlib type-feature
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
stdlib type-feature
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
build type-bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
-
stdlib topic-email type-feature
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Todos los issues de python/cpython
Issues similares
-
🐛 Bug 🔔 Pending processing
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
jumpserver/jumpserver#17584 ·
-
link-check link-check:sphinx-theme
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 90/100
modelscope/DiffSynth-Studio#1702 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
OpenHands/extensions#626 · 1 comentario ·