]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-112989: asyncio: Reduce overhead to connect sockets with SelectorEventLoop (#112991)
authorJ. Nick Koston <nick@koston.org>
Wed, 13 Dec 2023 00:29:21 +0000 (14:29 -1000)
committerGitHub <noreply@github.com>
Wed, 13 Dec 2023 00:29:21 +0000 (16:29 -0800)
_ensure_fd_no_transport had a KeyError in the success path

Lib/asyncio/selector_events.py
Misc/NEWS.d/next/Library/2023-12-12-05-48-17.gh-issue-112989.ZAa_eq.rst [new file with mode: 0644]

index d521b4e2e255a9f64411fd1c76542eb18ef3aaca..dcd5e0aa345029a3bf745734c10b8baf5dea8f56 100644 (file)
@@ -261,15 +261,11 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
             except (AttributeError, TypeError, ValueError):
                 # This code matches selectors._fileobj_to_fd function.
                 raise ValueError(f"Invalid file object: {fd!r}") from None
-        try:
-            transport = self._transports[fileno]
-        except KeyError:
-            pass
-        else:
-            if not transport.is_closing():
-                raise RuntimeError(
-                    f'File descriptor {fd!r} is used by transport '
-                    f'{transport!r}')
+        transport = self._transports.get(fileno)
+        if transport and not transport.is_closing():
+            raise RuntimeError(
+                f'File descriptor {fd!r} is used by transport '
+                f'{transport!r}')
 
     def _add_reader(self, fd, callback, *args):
         self._check_closed()
diff --git a/Misc/NEWS.d/next/Library/2023-12-12-05-48-17.gh-issue-112989.ZAa_eq.rst b/Misc/NEWS.d/next/Library/2023-12-12-05-48-17.gh-issue-112989.ZAa_eq.rst
new file mode 100644 (file)
index 0000000..ceeab8c
--- /dev/null
@@ -0,0 +1 @@
+Reduce overhead to connect sockets with :mod:`asyncio` SelectorEventLoop.