]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.12] gh-109047: concurrent.futures catches RuntimeError (#109810) (#110126)
authorVictor Stinner <vstinner@python.org>
Mon, 2 Oct 2023 15:47:10 +0000 (17:47 +0200)
committerGitHub <noreply@github.com>
Mon, 2 Oct 2023 15:47:10 +0000 (17:47 +0200)
commit356de021d7dc02d4803627c0807c0950f7453754
tree23123500d6b299c5aa722e2684533e910b46b748
parent41eb0c728653d2dfc0f9b4529557288069b6047a
[3.12] gh-109047: concurrent.futures catches RuntimeError (#109810) (#110126)

gh-109047: concurrent.futures catches PythonFinalizationError (#109810)

concurrent.futures: The *executor manager thread* now catches
exceptions when adding an item to the *call queue*. During Python
finalization, creating a new thread can now raise RuntimeError. Catch
the exception and call terminate_broken() in this case.

Add test_python_finalization_error() to test_concurrent_futures.

concurrent.futures._ExecutorManagerThread changes:

* terminate_broken() no longer calls shutdown_workers() since the
  call queue is no longer working anymore (read and write ends of
  the queue pipe are closed).
* terminate_broken() now terminates child processes, not only
  wait until they complete.
* _ExecutorManagerThread.terminate_broken() now holds shutdown_lock
  to prevent race conditons with ProcessPoolExecutor.submit().

multiprocessing.Queue changes:

* Add _terminate_broken() method.
* _start_thread() sets _thread to None on exception to prevent
  leaking "dangling threads" even if the thread was not started
  yet.

(cherry picked from commit 635184212179b0511768ea1cd57256e134ba2d75)
Lib/concurrent/futures/process.py
Lib/multiprocessing/queues.py
Lib/test/test_concurrent_futures/test_process_pool.py
Misc/NEWS.d/next/Library/2023-09-25-02-11-14.gh-issue-109047.b1TrqG.rst [new file with mode: 0644]