-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-32309: Implement asyncio.to_thread() #20143
bpo-32309: Implement asyncio.to_thread() #20143
Conversation
Co-authored-by: Yury Selivanov <[email protected]>
Co-authored-by: Chris Jerdonek <[email protected]>
/cc @1st1 |
This looks great to me. Please don't merge before @asvetlov and @cjerdonek approve. |
Is the name finalised? I saw the discussion about I would suggest create_task: Wrap the coroutine into a Task and schedule its execution. Return the Task object. create_thread: Wrap the function in a thread and start its execution. Return a future object. If you see what I mean? The functions are very similar but one is for coros concurrently in the event loop and the other is for functions concurrently in threads. |
Thanks. @tmewett I think the proposed name is good enough. Re: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a little doubt for the documentation text; the code itself and test are fine.
@aeros Looks like everybody approves this so you can go ahead and merge! Next todo:
|
Awesome, thanks for the reviews @1st1, @cjerdonek, and @asvetlov! I'll discuss the documentation a bit more w/ Andrew regarding the examples, and then proceed w/ merging it. |
Co-authored-by: Andrew Svetlov <[email protected]>
Thanks for the review as well @methane. :-) |
This occurred from a minor doctest warning, apparently having tildes in the code comments of example code is flagged as "suspicious". The latest commit should address it. |
@aeros: Status check is done, and it's a success ✅ . |
Note that this missed the 3.9 boat; it's now merged into 3.10. The whatsnew entry should be moved accordingly :) (The documentation needs the appropriate |
Currently, I'm reaching out to Łukasz to see if we could consider including this in 3.9b2 since it was so close to the deadline (it's been a WIP since last year and would have otherwise made it on-time, if not for some last minute changes). If he decides that it's too late, I'll update the whatsnew entry. (I'll also add the |
Thanks @aeros for the PR 🌮🎉.. I'm working now to backport this PR to: 3.9. |
GH-20212 is a backport of this pull request to the 3.9 branch. |
Implements `asyncio.to_thread`, a coroutine for asynchronously running IO-bound functions in a separate thread without blocking the event loop. See the discussion starting from [here](https://github.com/python/cpython/pull/18410GH-issuecomment-628930973) in pythonGH-18410 for context. Automerge-Triggered-By: @aeros (cherry picked from commit cc2bbc2) Co-authored-by: Kyle Stanley <[email protected]>
Implements `asyncio.to_thread`, a coroutine for asynchronously running IO-bound functions in a separate thread without blocking the event loop. See the discussion starting from [here](https://github.com/python/cpython/pull/18410GH-issuecomment-628930973) in GH-18410 for context. Automerge-Triggered-By: @aeros (cherry picked from commit cc2bbc2) Co-authored-by: Kyle Stanley <[email protected]>
Allows contextvars from the main thread to be accessed in the separate thread used in `asyncio.to_thread()`. See the [discussion](#20143 (comment)) in GH-20143 for context. Automerge-Triggered-By: @aeros
…GH-20278) Allows contextvars from the main thread to be accessed in the separate thread used in `asyncio.to_thread()`. See the [discussion](https://github.com/python/cpython/pull/20143GH-discussion_r427808225) in pythonGH-20143 for context. Automerge-Triggered-By: @aeros (cherry picked from commit 0f56263) Co-authored-by: Kyle Stanley <[email protected]>
Allows contextvars from the main thread to be accessed in the separate thread used in `asyncio.to_thread()`. See the [discussion](https://github.com/python/cpython/pull/20143GH-discussion_r427808225) in GH-20143 for context. Automerge-Triggered-By: @aeros (cherry picked from commit 0f56263) Co-authored-by: Kyle Stanley <[email protected]>
Implements `asyncio.to_thread`, a coroutine for asynchronously running IO-bound functions in a separate thread without blocking the event loop. See the discussion starting from [here](python#18410 (comment)) in pythonGH-18410 for context. Automerge-Triggered-By: @aeros
…GH-20278) Allows contextvars from the main thread to be accessed in the separate thread used in `asyncio.to_thread()`. See the [discussion](python#20143 (comment)) in pythonGH-20143 for context. Automerge-Triggered-By: @aeros
Implements
asyncio.to_thread
, a coroutine for asynchronously running IO-bound functions in a separate thread without blocking the event loop. See the discussion starting from here in GH-18410 for context.https://bugs.python.org/issue32309
Automerge-Triggered-By: @aeros