You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add support for all_errors to asyncio.create_connection #93973
As a result of the discussion on #74166, @iritkatriel added the all_errors keyword argument to socket.py:create_connection. When set to True, multiple exceptions are raised using an ExceptionGroup instead of a single OSError with the messages combined. I propose adding the same all_errors keyword to asyncio.create_connection, which would raise an ExceptionGroup in the case of connection errors (not for other errors, however).
Pitch
An ExceptionGroup is much nicer to handle than parsing through a concatenated string. An issue in the websockets library indicates that developers would like that for asyncio.create_connection as well. I personally ran into it myself as well.
Example usage:
async def check_ports(host: str, start: int, end: int, max=10):
for port in range(start, end):
try:
future = asyncio.open_connection(host=host, port=port, all_errors=True)
r, w = await asyncio.wait_for(future, timeout=timeout)
yield port
w.close()
except* ConnectionRefusedError:
pass
except* asyncio.TimeoutError:
pass
Activity
gvanrossum commentedon Sep 4, 2022
Sounds like a useful feature indeed.
gh-93973: Add all_errors to asyncio.create_connection (#93974)
kumaraditya303 commentedon Sep 5, 2022
Fixed by #93974