summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-05-31 00:26:20 -0700
committerGitHub <noreply@github.com>2020-05-31 00:26:20 -0700
commitcdb015b7ed58ee2babf552001374c278219854e1 (patch)
treef5e66d38ece32f20f46633355f0a4d0aa9b6f72f
parentbpo-40829: Add a what's new entry about deprecation of shuffle's random param... (diff)
downloadcpython-cdb015b7ed58ee2babf552001374c278219854e1.tar.gz
cpython-cdb015b7ed58ee2babf552001374c278219854e1.tar.bz2
cpython-cdb015b7ed58ee2babf552001374c278219854e1.zip
Fix asyncio.to_thread() documented return type (GH-20547)
When I wrote the documentation for `asyncio.to_thread()`, I mistakenly assumed that `return await loop.run_in_executor(...)` within an async def function would return a Future. In reality, it returns a coroutine. This likely won't affect typical usage of `asyncio.to_thread()`, but it's important for the documentation to be correct here. In general, we also tend to avoid returning futures from high-level APIs in asyncio. (cherry picked from commit 2b201369b435a4266bda5b895e3b615dbe28ea6e) Co-authored-by: Kyle Stanley <aeros167@gmail.com>
-rw-r--r--Doc/library/asyncio-task.rst3
-rw-r--r--Lib/asyncio/threads.py2
2 files changed, 2 insertions, 3 deletions
diff --git a/Doc/library/asyncio-task.rst b/Doc/library/asyncio-task.rst
index 847363b134a..21824ca537f 100644
--- a/Doc/library/asyncio-task.rst
+++ b/Doc/library/asyncio-task.rst
@@ -614,8 +614,7 @@ Running in Threads
allowing context variables from the event loop thread to be accessed in the
separate thread.
- Return an :class:`asyncio.Future` which represents the eventual result of
- *func*.
+ Return a coroutine that can be awaited to get the eventual result of *func*.
This coroutine function is primarily intended to be used for executing
IO-bound functions/methods that would otherwise block the event loop if
diff --git a/Lib/asyncio/threads.py b/Lib/asyncio/threads.py
index 51e0ba95d82..34b7513a420 100644
--- a/Lib/asyncio/threads.py
+++ b/Lib/asyncio/threads.py
@@ -17,7 +17,7 @@ async def to_thread(func, /, *args, **kwargs):
allowing context variables from the main thread to be accessed in the
separate thread.
- Return an asyncio.Future which represents the eventual result of *func*.
+ Return a coroutine that can be awaited to get the eventual result of *func*.
"""
loop = events.get_running_loop()
ctx = contextvars.copy_context()