Inconsistent behavior of asyncio.Server.wait_closed
in Python 3.12 versus earlier releases
#120866
Labels
asyncio.Server.wait_closed
in Python 3.12 versus earlier releases
#120866
Bug report
Bug description:
The issue fixed in #111424 is only available in Python 3.12. As a result, the example below prematurely closes a connection when using an older Python version. The old behavior may lead to bugs that are hard to catch, and the difference in behavior implies that applications must use workarounds to support multiple Python versions.
If backporting the fix is not an option, it would be helpful to add a note to the documentation of
asyncio.Server.wait_closed
that it changed in Python 3.12.Related issues: #104344 (same cause, going from 3.11 to 3.12), #79033
minimal example
server.py
client.py
This is a minimal working example distilled from a more complex use case where the
stop_event
is set in a function that receives the request and creates the response.One possible workaround is to postpone setting the
stop_event
to the end of the handler function. That would be easy in this example, but more involved in the case where I ran into this issue.Python 3.12 and 3.13 output
server.py
client.py
Python 3.9, 3.10 and 3.11 output
Note that the handler does not complete when it receives STOP.
server.py
client.py
CPython versions tested on:
3.9, 3.10, 3.11, 3.12, 3.13
Operating systems tested on:
Linux
The text was updated successfully, but these errors were encountered: