From 2a5ba3eab646b75b419dc7f57b7af5ed4efc43db Mon Sep 17 00:00:00 2001 From: Yash Date: Sun, 16 Nov 2025 15:11:06 +0530 Subject: [PATCH 1/2] gh-141617: Add missing result() call in concurrent.futures example --- Doc/library/concurrent.futures.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/concurrent.futures.rst b/Doc/library/concurrent.futures.rst index c2e2f7f820f4ef..7cad0fd1473c35 100644 --- a/Doc/library/concurrent.futures.rst +++ b/Doc/library/concurrent.futures.rst @@ -151,7 +151,7 @@ And:: print(f.result()) executor = ThreadPoolExecutor(max_workers=1) - executor.submit(wait_on_future) + executor.submit(wait_on_future).result() .. class:: ThreadPoolExecutor(max_workers=None, thread_name_prefix='', initializer=None, initargs=()) From 6dd6b65fe5a1bdd2b30625dac0811c14268bd504 Mon Sep 17 00:00:00 2001 From: Yash Date: Mon, 17 Nov 2025 15:50:05 +0530 Subject: [PATCH 2/2] gh-141617: Clarify ThreadPoolExecutor deadlock example in docs --- Doc/library/concurrent.futures.rst | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Doc/library/concurrent.futures.rst b/Doc/library/concurrent.futures.rst index 7cad0fd1473c35..ec56a361b89a51 100644 --- a/Doc/library/concurrent.futures.rst +++ b/Doc/library/concurrent.futures.rst @@ -40,7 +40,9 @@ Executor Objects with ThreadPoolExecutor(max_workers=1) as executor: future = executor.submit(pow, 323, 1235) print(future.result()) - + # Note: calling future.result() outside this with statement would work fine, + # but calling it here is safe because we print it immediately and the executor + # can complete the task before the context manager exits. .. method:: map(fn, *iterables, timeout=None, chunksize=1, buffersize=None) Similar to :func:`map(fn, *iterables) ` except: @@ -152,7 +154,9 @@ And:: executor = ThreadPoolExecutor(max_workers=1) executor.submit(wait_on_future).result() - + # Note: calling future.result() here would cause a deadlock because the single + # worker thread is already executing wait_on_future(), which itself is waiting + # for a result from the same executor. .. class:: ThreadPoolExecutor(max_workers=None, thread_name_prefix='', initializer=None, initargs=())