Requiring A Current Thread State for PyThreadState_Clear(), etc. is Problematic
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Accessibilité débutants
- 25/100
Piste de recherche
Commencez par retracer PyThreadState_Clear() et PyInterpreterState_Clear(), y compris les cas de cycle de vie résumés dans gh-101308, et identifiez où l’état du thread courant est requis. C’est terminé lorsque les API d’effacement conservent leur exigence de GIL sans dépendre d’un état de thread en cours d’invalidation, tandis que les invariants de cycle de vie listés restent satisfaits.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
In PyThreadState_Clear() and PyInterpreterState_Clear() the code expects a "current" thread state (i.e. set by PyThreadState_Swap()) to be set. Presumably this is for the following:
- to ensure the GIL is held
- to use for logging audit events (actually only needs the current interpreter?)
- to use in object finalizers for objects held by the target thread/interpreter state
For PyThreadState_Clear(), this is a problem when the current thread state is also the target thread state, since the function is progressively rendering the thread state unusable. For PyInterpreterState_Clear() the "current" thread state must belong to the target interpreter, but will be rendered unusable before it's potentially needed.
(FWIW, it isn't clear to me yet why we don't see frequent crashes from this already (at least when we're clearing the main interpreter during finalization). I do suspect that this contributes to some of the occasional CI failures we see relative to finalization.)
Ideally auditing and the various object finalizers could work without having a current thread state, especially in the case where the current thread state could only possibly be the one getting cleared. Could we split up PyThreadState so at least the problematic part is guaranteed not be used in PyThreadState_Clear() or PyInterpreterState_Clear()? Are there other complexities we have to deal with?
(Note that we'd still require that the GIL be held by the current OS thread when PyThreadState_Clear() or PyInterpreterState_Clear() are called.)
FTR, in gh-101308 I noted various cases where the lifecycle of thread states has an unexpected status. Pretty much all of them relate `PyThreadState_Clear()` requiring a current thread state.
Dealing with the main issue above would make it trivial to address the following:
- an "active" thread state (i.e. "current", holding the GIL) must be "bound" (to an OS thread) already
- a "bound" thread state must be "alive" (initialized but not finalizing)
- binding a thread state should be done separately from
PyThreadState_New() - the thread state passed to
PyThreadState_Clear()should no longer be "active" or "bound" - the current thread state must belong to the target interpreter of
PyThreadState_Clear() - the current thread state must belong to the target interpreter of
PyInterpreterState_Clear()(for the main interpreter it must be the main thread)
- Langage dominant
- Python
- Étoiles
- 77.2k
- Forks
- 36k
- Merge moyen
- 1 j 9 h
- PR mergées (30 j)
- 558
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de python/cpython
-
docs pending
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
-
stdlib type-feature
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
-
stdlib type-feature
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
-
build type-bug
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
-
stdlib topic-email type-feature
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
Toutes les issues de python/cpython
Issues similaires
-
fix: inaccuracy ⚠️
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
uabrc/uabrc.github.io#1255 · 1 commentaire ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
ethereum-optimism/factory#64 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 90/100
duckdb/duckdb-python#627 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
-
Add link for tutorial Ouvertedocumentation
Difficulté 1/5 Moins d'une heure Accessibilité débutants 78/100
Qiskit/qiskit-addon-sqd#376 ·