diff --git a/Doc/library/concurrent.futures.rst b/Doc/library/concurrent.futures.rst index c2e2f7f820f4ef..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: @@ -151,8 +153,10 @@ And:: print(f.result()) executor = ThreadPoolExecutor(max_workers=1) - executor.submit(wait_on_future) - + 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=())