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 runner.serve_forever() #7688

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

vsmaxim
Copy link

@vsmaxim vsmaxim commented Oct 9, 2023

What do these changes do?

This is a continuation of work from #4378. I've dropped cleanup call on serve_forever() task cancellation
and updated the documentation accordingly.

Are there changes in behavior for the user?

No.

Related issue number

#2746

Original attempt from asvetlov: master...server_forever

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_id>.<type> for example (588.bugfix)
    • if you don't have an issue_id change it to the pr id after creating the pr
    • ensure type is one of the following:
      • .feature: Signifying a new feature.
      • .bugfix: Signifying a bug fix.
      • .doc: Signifying a documentation improvement.
      • .removal: Signifying a deprecation or removal of public API.
      • .misc: A ticket has been closed, but it is not of interest to users.
    • Make sure to use full sentences with correct case and punctuation, for example: "Fix issue with non-ascii contents in doctest text files."

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Oct 9, 2023
tests/test_web_runner.py Dismissed Show dismissed Hide dismissed
aiohttp/web_runner.py Dismissed Show dismissed Hide dismissed
@codecov
Copy link

codecov bot commented Oct 9, 2023

Codecov Report

Attention: Patch coverage is 94.28571% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 97.36%. Comparing base (4601183) to head (b05fcaa).
Report is 480 commits behind head on master.

Files Patch % Lines
aiohttp/web_runner.py 83.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           master    #7688    +/-   ##
========================================
  Coverage   97.36%   97.36%            
========================================
  Files         106      106            
  Lines       31541    31661   +120     
  Branches     3593     3625    +32     
========================================
+ Hits        30709    30826   +117     
- Misses        630      631     +1     
- Partials      202      204     +2     
Flag Coverage Δ
CI-GHA 97.28% <94.28%> (+<0.01%) ⬆️
OS-Linux 96.95% <94.28%> (+<0.01%) ⬆️
OS-Windows 95.42% <94.28%> (+0.02%) ⬆️
OS-macOS 96.61% <94.28%> (+0.01%) ⬆️
Py-3.10.11 95.35% <94.28%> (+0.02%) ⬆️
Py-3.10.13 96.81% <94.28%> (+<0.01%) ⬆️
Py-3.11.5 96.49% <94.28%> (-0.03%) ⬇️
Py-3.8.10 95.32% <94.28%> (+0.02%) ⬆️
Py-3.8.18 96.74% <94.28%> (+<0.01%) ⬆️
Py-3.9.13 95.31% <94.28%> (+0.02%) ⬆️
Py-3.9.18 96.77% <94.28%> (+<0.01%) ⬆️
Py-pypy7.3.11 96.26% <94.28%> (-0.03%) ⬇️
VM-macos 96.61% <94.28%> (+0.01%) ⬆️
VM-ubuntu 96.95% <94.28%> (+<0.01%) ⬆️
VM-windows 95.42% <94.28%> (+0.02%) ⬆️

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.

@Dreamsorcerer
Copy link
Member

Dreamsorcerer commented Feb 27, 2024

Sorry for taking so long to look at this. I have a few questions about the implementation and expected behaviour:

  • The original attempt ran cleanup on cancellation. Should this still happen? Seems it would match the asyncio.Server behaviour which says "Cancellation of serve_forever task causes the server to be closed."
    • I see @asvetlov suggested we do an async context manager for this one instead, so I guess the current version is correct. Will need a second PR to add the context manager though.
  • The original also checks if there's any sites, should we include that check?
  • Along those same lines, should we call Site.start() for each site, so the user doesn't need to call that themselves? This would match the asyncio.Server behaviour which calls Server.start_serving() from within Server.serve_forever().
  • Should an explicit call to Runner.cleanup() cancel the future in serve_forever()? This would match asyncio.Server.close() which cancels the future.

:async:

Wait forever. Make sure to call :meth:`setup` prior calling this method.
Only one :meth:`serve_forever` task is allowed per one runner object.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Only one :meth:`serve_forever` task is allowed per one runner object.
Only one :meth:`serve_forever` task is allowed per runner object.

runner = make_runner()
task = loop.create_task(runner.serve_forever())
await asyncio.sleep(0.01)
with pytest.raises(RuntimeError):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use the match argument to match the text of the exception in these?
The codecov comment suggests this test isn't working correctly.

@Dreamsorcerer Dreamsorcerer added the backport-3.10 Trigger automatic backporting to the 3.10 release branch by Patchback robot label Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-3.10 Trigger automatic backporting to the 3.10 release branch by Patchback robot bot:chronographer:provided There is a change note present in this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants