misc: simplify running non-async callback using asyncio.to_thread#1661
Merged
JrooTJunior merged 2 commits intoaiogram:dev-3.xfrom Apr 2, 2025
Merged
misc: simplify running non-async callback using asyncio.to_thread#1661JrooTJunior merged 2 commits intoaiogram:dev-3.xfrom
JrooTJunior merged 2 commits intoaiogram:dev-3.xfrom
Conversation
✔️ Changelog found.Thank you for adding a description of the changes |
Olegt0rr
reviewed
Apr 1, 2025
| context = contextvars.copy_context() | ||
| wrapped = partial(context.run, wrapped) | ||
| return await loop.run_in_executor(None, wrapped) | ||
| return await asyncio.to_thread(wrapped) |
Contributor
There was a problem hiding this comment.
Are you sure copy context is not necessary anymore?
Contributor
Author
There was a problem hiding this comment.
asyncio.to_thread does the same thing, gets the current loop, context and runs it in the executor.
Olegt0rr
approved these changes
Apr 1, 2025
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## dev-3.x #1661 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 511 511
Lines 12531 12528 -3
=========================================
- Hits 12531 12528 -3
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
JrooTJunior
approved these changes
Apr 2, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Replaced
loop.run_in_executorwithasyncio.to_threadfor improved readability and consistency.This change does not affect functionality but simplifies the code.
No related issue.
Type of change
How Has This Been Tested?
Since this is a non-functional change, no new tests were required.
Existing tests were run to ensure there were no regressions.
Test Configuration:
Checklist: