FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.12] gh-79033: Try to fix asyncio.Server.wait_closed() again (GH-111336) by miss-islington · Pull Request #111424 · python/cpython · GitHub

Repository navigation

[3.12] gh-79033: Try to fix asyncio.Server.wait_closed() again (GH-111336) - #111424

Merged
willingc merged 1 commit into
python:3.12from
miss-islington:backport-2655369-3.12
Oct 28, 2023
Merged

willingc merged 1 commit into
python:3.12from
miss-islington:backport-2655369-3.12

Conversation

miss-islington commented Oct 28, 2023 •
edited by github-actions Bot
Loading

Copy link
Copy Markdown
Contributor
  • Try to fix asyncio.Server.wait_closed() again

I identified the condition that wait_closed() is intended
to wait for: the server is closed and there are no more
active connections.

When this condition first becomes true, _wakeup() is called
(either from close() or from _detach()) and it sets _waiters
to None. So we just check for self._waiters is None; if it's
not None, we know we have to wait, and do so.

A problem was that the new test introduced in 3.12 explicitly
tested that wait_closed() returns immediately when the server
is not closed but there are currently no active connections.
This was a mistake (probably a misunderstanding of the intended
semantics). I've fixed the test, and added a separate test that
checks exactly for this scenario.

I also fixed an oddity where in _wakeup() the result of the
waiter was set to the waiter itself. This result is not used
anywhere and I changed this to None, to avoid a GC cycle.

  • Update Lib/asyncio/base_events.py

(cherry picked from commit 2655369)

Co-authored-by: Guido van Rossum guido@python.org
Co-authored-by: Carol Willing carolcode@willingconsulting.com


📚 Documentation preview 📚: https://cpython-previews--111424.org.readthedocs.build/

…GH-111336)

* Try to fix asyncio.Server.wait_closed() again

I identified the condition that `wait_closed()` is intended
to wait for: the server is closed *and* there are no more
active connections.

When this condition first becomes true, `_wakeup()` is called
(either from `close()` or from `_detach()`) and it sets `_waiters`
to `None`. So we just check for `self._waiters is None`; if it's
not `None`, we know we have to wait, and do so.

A problem was that the new test introduced in 3.12 explicitly
tested that `wait_closed()` returns immediately when the server
is *not* closed but there are currently no active connections.
This was a mistake (probably a misunderstanding of the intended
semantics). I've fixed the test, and added a separate test that
checks exactly for this scenario.

I also fixed an oddity where in `_wakeup()` the result of the
waiter was set to the waiter itself. This result is not used
anywhere and I changed this to `None`, to avoid a GC cycle.

* Update Lib/asyncio/base_events.py

---------

(cherry picked from commit 2655369)

Co-authored-by: Guido van Rossum <guido@python.org>
Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL