Worker management race conditions in `ThreadPoolExecutor` and `ProcessPoolExecutor`
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
We have tests that ThreadPoolExecutor and ProcessPoolExecutor reuse workers. The test wait for the previous task to complete before submitting the next task.
The problem is that the tasks are potentially completed before the thread or process is marked as idle. Calling Future.result() doesn't guarantee that there is an idle worker. This happens much more frequently with the GIL disabled, but it can happen with the GIL enabled too if you have an unlucky GIL switch.
For example, you can reliably trigger the problem with the GIL enabled by adding a short time.sleep(0.01) immediately after the work_item.run() call in:
https://github.com/python/cpython/blob/29829b58a8328a7c2ccacaa74c1d7d120a5e5ca5/Lib/concurrent/futures/thread.py#L92
It's not clear to me if this is just a problem with the unit tests or an actual bug with the executor implementation.
Linked PRs
- gh-117355
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 i test di riutilizzo citati in Lib/test/test_concurrent_futures/test_thread_pool.py e con il codice del ciclo di vita dei worker in Lib/concurrent/futures/thread.py; esamina anche i percorsi corrispondenti di ProcessPoolExecutor. Determina se la race condition richiede una sincronizzazione più forte dei test o una modifica all’executor, quindi esegui la suite di test concurrent-futures e assicurati che il riutilizzo dei worker sia affidabile sia nell’esecuzione con il GIL abilitato sia nell’esecuzione con il GIL disabilitato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- backend, distributed-systems, testing-qa
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 25/100