Skip to content

Commit 7e2d93f

Browse files
authored
gh-112989: asyncio: Reduce overhead to connect sockets with SelectorEventLoop (#112991)
_ensure_fd_no_transport had a KeyError in the success path
1 parent a3c0318 commit 7e2d93f

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

Lib/asyncio/selector_events.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -261,15 +261,11 @@ def _ensure_fd_no_transport(self, fd):
261261
except (AttributeError, TypeError, ValueError):
262262
# This code matches selectors._fileobj_to_fd function.
263263
raise ValueError(f"Invalid file object: {fd!r}") from None
264-
try:
265-
transport = self._transports[fileno]
266-
except KeyError:
267-
pass
268-
else:
269-
if not transport.is_closing():
270-
raise RuntimeError(
271-
f'File descriptor {fd!r} is used by transport '
272-
f'{transport!r}')
264+
transport = self._transports.get(fileno)
265+
if transport and not transport.is_closing():
266+
raise RuntimeError(
267+
f'File descriptor {fd!r} is used by transport '
268+
f'{transport!r}')
273269

274270
def _add_reader(self, fd, callback, *args):
275271
self._check_closed()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Reduce overhead to connect sockets with :mod:`asyncio` SelectorEventLoop.

0 commit comments

Comments
 (0)