cpython/Lib/asyncio
Guido van Rossum 2655369559
gh-79033: Try to fix asyncio.Server.wait_closed() again (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

---------

Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
2023-10-28 18:04:29 +00:00
..
__init__.py gh-106075: add `asyncio.taskgroups.__all__` to `asyncio.__all__` (#106090) 2023-06-26 07:54:03 +00:00
__main__.py
base_events.py gh-79033: Try to fix asyncio.Server.wait_closed() again (GH-111336) 2023-10-28 18:04:29 +00:00
base_futures.py gh-84623: Remove unused imports in stdlib (#93773) 2022-06-13 16:28:41 +02:00
base_subprocess.py GH-100133: fix `asyncio` subprocess losing `stderr` and `stdout` output (#100154) 2022-12-21 15:20:26 +05:30
base_tasks.py gh-97696: asyncio eager tasks factory (#102853) 2023-05-01 15:10:13 -06:00
constants.py GH-82448: Add thread timeout for loop.shutdown_default_executor (#97561) 2022-09-28 10:39:42 -07:00
coroutines.py GH-102748: remove legacy support for generator based coroutines from `asyncio.iscoroutine` (#102749) 2023-03-16 20:28:10 +05:30
events.py gh-106634: Corrected minor asyncio doc issues (#106671) 2023-07-13 13:21:13 +05:30
exceptions.py bpo-43352: Add a Barrier object in asyncio lib (GH-24903) 2022-03-26 00:01:21 +02:00
format_helpers.py
futures.py gh-93453: No longer create an event loop in get_event_loop() (#98440) 2022-12-06 18:42:12 +01:00
locks.py gh-97545: Make Semaphore run faster. (#97549) 2022-09-26 16:38:00 -07:00
log.py
mixins.py bpo-46796: Simplify handling of removed parameter "loop" in asyncio (GH-31431) 2022-02-21 13:25:52 +02:00
proactor_events.py gh-99941: Ensure that asyncio.Protocol.data_received receives immutable bytes (#100053) 2022-12-10 15:07:02 -08:00
protocols.py bpo-46741: Update `asyncio.protocols.BufferedProtocol` docstring (31327) 2022-02-15 18:39:28 +02:00
queues.py bpo-46796: Simplify handling of removed parameter "loop" in asyncio (GH-31431) 2022-02-21 13:25:52 +02:00
runners.py GH-99388: add `loop_factory` parameter to `asyncio.run` (#99462) 2022-11-14 10:18:51 -08:00
selector_events.py gh-106527: asyncio: optimize to add/remove readers and writers (#106528) 2023-07-22 21:07:40 +00:00
sslproto.py gh-108903: Remove unneeded `lambda`s from `asyncio` (GH-108904) 2023-09-05 18:11:12 +03:00
staggered.py
streams.py Remove loop from docstring for asyncio.streams.open_connection (#108528) 2023-09-26 20:34:15 -07:00
subprocess.py gh-109709: Fix asyncio test_stdin_broken_pipe() (#109710) 2023-09-22 15:29:42 +02:00
taskgroups.py gh-111085: Fix invalid state handling in TaskGroup and Timeout (#111111) 2023-10-21 22:18:34 +03:00
tasks.py gh-110961: Fixed asyncio.wait docstring to remove deprecated coroutine reference (#111017) 2023-10-18 04:40:26 +00:00
threads.py Trivial typo in docstring 2021-07-31 06:36:10 +02:00
timeouts.py gh-111085: Fix invalid state handling in TaskGroup and Timeout (#111111) 2023-10-21 22:18:34 +03:00
transports.py Remove trailing spaces (GH-31695) 2022-03-05 17:47:00 +02:00
trsock.py bpo-43232: Remove previously deprecated methods on TransportSocket (GH-24538) 2021-06-30 09:19:09 +03:00
unix_events.py gh-110205: Fix asyncio ThreadedChildWatcher._join_threads() (#110884) 2023-10-27 15:44:12 -07:00
windows_events.py gh-110771: Decompose run_forever() into parts (#110773) 2023-10-13 14:12:32 +00:00
windows_utils.py