concurrent.futures.ProcessPoolExecutor raises during shutdown
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 35.9k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Bug report
Bug description:
from concurrent.futures import ProcessPoolExecutor as Pool
def nope():
pass
def mk_done(pool):
def done(_fut):
pool.shutdown(wait=True)
return done
if __name__ == "__main__":
pool = Pool()
future = pool.submit(nope)
future.add_done_callback(mk_done(pool))
ProcessPoolExecutor invokes future done callbacks from its manager thread. When one of those future callbacks invokes ProcessPoolExecutor.shutdown(), shut down fails with a RuntimeError: cannot join current thread because the implementation joins the manager thread without protecting against self-joins.
The relevant lines Lib/concurrent/futures/process.py:845-846 currently read:
if self._executor_manager_thread is not None and wait:
self._executor_manager_thread.join()
but should probably be updated to:
t = self._executor_manager_thread
if t is not None and wait and threading.current_thread() != t:
self._executor_manager_thread.join()
Invoking shutdown(False) avoids the problem but also makes it impossible to wait for pool completion. A more general solution would be to deprecate the wait parameter for shutdown, never waiting in that method, and add a separate method, say wait_for_shutdown, that uses a threading.Event to wake any waiting threads. Alas, correctly setting that Event is going to be a bit involved.
While I tested on 3.12, the bug is also present in 3.13 and current.
CPython versions tested on:
3.12
Operating systems tested on:
macOS
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginnen Sie mit der Ausführung der bereitgestellten ProcessPoolExecutor-Reproduktion und untersuchen Sie anschließend Lib/concurrent/futures/process.py im Bereich der Zeilen 845–846 sowie den shutdown-Einstiegspunkt. Fügen Sie eine Abdeckung für shutdown(wait=True) aus einem Future-Callback hinzu und überprüfen Sie, dass der Callback ohne einen self-join-Fehler abgeschlossen wird, während das Abschließen des Pools weiterhin abgewartet werden kann.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- backend
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 52/100