-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backport asyncio socket connection performance improvement (#254)
- Loading branch information
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
python/3.11/gh-112989-asyncio-Reduce-overhead-to-connect-sockets.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
From 7e2d93f30b157e414924c32232bb748c8f66c828 Mon Sep 17 00:00:00 2001 | ||
From: "J. Nick Koston" <[email protected]> | ||
Date: Tue, 12 Dec 2023 14:29:21 -1000 | ||
Subject: [PATCH] gh-112989: asyncio: Reduce overhead to connect sockets with | ||
SelectorEventLoop (#112991) | ||
|
||
_ensure_fd_no_transport had a KeyError in the success path | ||
--- | ||
Lib/asyncio/selector_events.py | 14 +++++--------- | ||
.../2023-12-12-05-48-17.gh-issue-112989.ZAa_eq.rst | 1 + | ||
2 files changed, 6 insertions(+), 9 deletions(-) | ||
create mode 100644 Misc/NEWS.d/next/Library/2023-12-12-05-48-17.gh-issue-112989.ZAa_eq.rst | ||
|
||
diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py | ||
index d521b4e2e2..dcd5e0aa34 100644 | ||
--- a/Lib/asyncio/selector_events.py | ||
+++ b/Lib/asyncio/selector_events.py | ||
@@ -261,15 +261,11 @@ def _ensure_fd_no_transport(self, fd): | ||
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() | ||
|
39 changes: 39 additions & 0 deletions
39
python/3.12/gh-112989-asyncio-Reduce-overhead-to-connect-sockets.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
From 7e2d93f30b157e414924c32232bb748c8f66c828 Mon Sep 17 00:00:00 2001 | ||
From: "J. Nick Koston" <[email protected]> | ||
Date: Tue, 12 Dec 2023 14:29:21 -1000 | ||
Subject: [PATCH] gh-112989: asyncio: Reduce overhead to connect sockets with | ||
SelectorEventLoop (#112991) | ||
|
||
_ensure_fd_no_transport had a KeyError in the success path | ||
--- | ||
Lib/asyncio/selector_events.py | 14 +++++--------- | ||
.../2023-12-12-05-48-17.gh-issue-112989.ZAa_eq.rst | 1 + | ||
2 files changed, 6 insertions(+), 9 deletions(-) | ||
create mode 100644 Misc/NEWS.d/next/Library/2023-12-12-05-48-17.gh-issue-112989.ZAa_eq.rst | ||
|
||
diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py | ||
index d521b4e2e2..dcd5e0aa34 100644 | ||
--- a/Lib/asyncio/selector_events.py | ||
+++ b/Lib/asyncio/selector_events.py | ||
@@ -261,15 +261,11 @@ def _ensure_fd_no_transport(self, fd): | ||
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() | ||
|