An interpreter can start running during `_interpreters.destroy`
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Crash report
What happened?
Now that gh-126914 is out of the way, we can try and deal with some of the other issues related to multithreading and subinterpreters that couldn't get dealt with before. Namely, the is_running_main inside _interpreters.destroy doesn't account for the fact that the interpreter could start running again by another thread after that check has already passed.
Quick reproducer:
from threading import Thread
import _interpreters
interp = _interpreters.create()
def run():
_interpreters.run_string(interp, "1")
_interpreters.destroy(interp)
threads = [Thread(target=run) for _ in range(1000)]
for thread in threads:
thread.start()
for thread in threads:
thread.join()
I think the simplest fix would be to just disallow a subinterpreter from ever set "running main" again after that check has finished. I implemented this already in the (closed) gh-126696, but I'd like to try and refactor that a bit before just copying things over to a new PR.
cc @ericsnowcurrently, let me know if you have a better approach.
CPython versions tested on:
3.13, 3.14, CPython main branch
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
No response
Linked PRs
- gh-127044
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 con il percorso _interpreters.destroy e il relativo controllo is_running_main, quindi esegui il riproduttore con 1.000 thread usando _interpreters.run_string e _interpreters.destroy. Esamina la PR collegata gh-127044 e la gh-126696 chiusa a cui si fa riferimento; il lavoro è completato quando il riproduttore non consente più a un interprete di iniziare l’esecuzione durante la distruzione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- backend
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 25/100