Skip to content
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

Add distinction between error cases in TimerContext #10159

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

GDYendell
Copy link

What do these changes do?

This adds a distinct error message in the case that TimerContext is used within a task, but the task is on a different event loop.

Are there changes in behavior for the user?

The user will get a slightly different - and hopefully more useful - error message in the above case.

Is it a substantial burden for the maintainers to support this?

No.

Related issue number

Fixes #10153

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt
    • The format is <Name> <Surname>.
    • Please keep alphabetical order, the file is sorted by names.
  • Add a new news fragment into the CHANGES/ folder
    • name it <issue_or_pr_num>.<type>.rst (e.g. 588.bugfix.rst)

    • if you don't have an issue number, change it to the pull request
      number after creating the PR

      • .bugfix: A bug fix for something the maintainers deemed an
        improper undesired behavior that got corrected to match
        pre-agreed expectations.
      • .feature: A new behavior, public APIs. That sort of stuff.
      • .deprecation: A declaration of future API removals and breaking
        changes in behavior.
      • .breaking: When something public is removed in a breaking way.
        Could be deprecated in an earlier release.
      • .doc: Notable updates to the documentation structure or build
        process.
      • .packaging: Notes for downstreams about unobvious side effects
        and tooling. Changes in the test invocation considerations and
        runtime assumptions.
      • .contrib: Stuff that affects the contributor experience. e.g.
        Running tests, building the docs, setting up the development
        environment.
      • .misc: Changes that are hard to assign to any of the above
        categories.
    • Make sure to use full sentences with correct case and punctuation,
      for example:

      Fixed issue with non-ascii contents in doctest text files
      -- by :user:`contributor-gh-handle`.

      Use the past tense or the present tense a non-imperative mood,
      referring to what's changed compared to the last released version
      of this project.

@GDYendell GDYendell requested a review from asvetlov as a code owner December 11, 2024 16:52
@GDYendell
Copy link
Author

Let me know if you would like a test that checks the specific error messages for the different cases. Is there any relevant documentation to update for this change? I don't think it is worth adding an entry to CHANGES/ but I can do.

Copy link

codecov bot commented Dec 11, 2024

Codecov Report

Attention: Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.

Project coverage is 98.74%. Comparing base (3f07b1a) to head (6faaa4d).

Files with missing lines Patch % Lines
aiohttp/helpers.py 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #10159      +/-   ##
==========================================
- Coverage   98.75%   98.74%   -0.01%     
==========================================
  Files         122      122              
  Lines       36954    36956       +2     
  Branches     4411     4412       +1     
==========================================
- Hits        36494    36493       -1     
- Misses        313      316       +3     
  Partials      147      147              
Flag Coverage Δ
CI-GHA 98.63% <0.00%> (-0.01%) ⬇️
OS-Linux 98.32% <0.00%> (-0.01%) ⬇️
OS-Windows 96.17% <ø> (ø)
OS-macOS 97.42% <0.00%> (-0.02%) ⬇️
Py-3.10.11 97.27% <0.00%> (-0.01%) ⬇️
Py-3.10.15 97.80% <0.00%> (-0.01%) ⬇️
Py-3.11.10 97.85% <0.00%> (-0.06%) ⬇️
Py-3.11.9 97.32% <0.00%> (-0.03%) ⬇️
Py-3.12.7 98.38% <0.00%> (+<0.01%) ⬆️
Py-3.13.0 97.18% <0.00%> (-0.01%) ⬇️
Py-3.13.1 98.33% <0.00%> (-0.01%) ⬇️
Py-3.9.13 97.19% <0.00%> (-0.01%) ⬇️
Py-3.9.20 97.77% <0.00%> (+<0.01%) ⬆️
Py-pypy7.3.16 97.34% <0.00%> (-0.01%) ⬇️
VM-macos 97.42% <0.00%> (-0.02%) ⬇️
VM-ubuntu 98.32% <0.00%> (-0.01%) ⬇️
VM-windows 96.17% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

codspeed-hq bot commented Dec 11, 2024

CodSpeed Performance Report

Merging #10159 will degrade performances by 10.92%

Comparing GDYendell:timer-context-error (5ad9083) with master (0070045)

Summary

❌ 1 regressions
✅ 46 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark master GDYendell:timer-context-error Change
test_one_thousand_large_round_trip_websocket_text_messages[pyloop] 23.3 ms 26.1 ms -10.92%

@GDYendell GDYendell requested a review from webknjaz as a code owner December 11, 2024 17:02
@Dreamsorcerer Dreamsorcerer added bot:chronographer:skip This PR does not need to include a change note backport-3.11 Trigger automatic backporting to the 3.11 release branch by Patchback robot backport-3.12 Trigger automatic backporting to the 3.12 release branch by Patchback robot labels Dec 11, 2024
@Dreamsorcerer
Copy link
Member

Let me know if you would like a test that checks the specific error messages for the different cases.

Yeah, we'll want a test case for coverage.

Is there any relevant documentation to update for this change? I don't think it is worth adding an entry to CHANGES/ but I can do.

Agreed, leave it.

@Dreamsorcerer
Copy link
Member

I'm a little confused what happened to the coverage, it says master has coverage of the existing exception, but this change doesn't have coverage of either of the exceptions...

@Dreamsorcerer
Copy link
Member

...unless asyncio.current_task() is managing to cause a RuntimeError itself and the tests aren't checking the exception text..

@GDYendell
Copy link
Author

GDYendell commented Dec 12, 2024

...unless asyncio.current_task() is managing to cause a RuntimeError itself

Yep you're right. I have updated it to a try-except. Now the behaviour is correct. The original error case is still hit if used outside of an event loop entirely, as shown in the test. I get the new error in my application when used in the wrong event loop.

However, I am having trouble provoking the latter error case in a test, because the main event loop happens to have another task, so asyncio.current_task(loop=self._loop) does return a task, just not the one that the context manager is running in. I.e. asyncio.current_task(loop=self._loop) != asyncio.current_task(asyncio.get_running_loop())

Do you have any suggestions on how this could be done? Do you think this is now adding too much complication for the sake of an error message?

@Dreamsorcerer
Copy link
Member

...unless asyncio.current_task() is managing to cause a RuntimeError itself

Yep you're right. I have updated it to a try-except.

Odd, the docs don't seem to suggest such behaviour.

Do you have any suggestions on how this could be done? Do you think this is now adding too much complication for the sake of an error message?

I'm not too sure how to make it work. Maybe it's not worth the effort, but I've never used multiple loops before. Up to you if you want to continue pursuing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-3.11 Trigger automatic backporting to the 3.11 release branch by Patchback robot backport-3.12 Trigger automatic backporting to the 3.12 release branch by Patchback robot bot:chronographer:skip This PR does not need to include a change note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Timeout context manager should be used inside a task" slightly misleading
2 participants