-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Python 3.12, Drop Python 3.9 (#241)
- Loading branch information
Showing
12 changed files
with
312 additions
and
42 deletions.
There are no files selected for viewing
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
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
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
File renamed without changes.
30 changes: 15 additions & 15 deletions
30
python/3.9/asynctio_unix_events.patch → python/3.12/asynctio_unix_events.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 |
---|---|---|
@@ -1,16 +1,16 @@ | ||
diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py | ||
index f34a5b4b44..b1d0f1e61e 100644 | ||
--- a/Lib/asyncio/unix_events.py | ||
+++ b/Lib/asyncio/unix_events.py | ||
@@ -369,6 +369,11 @@ class _UnixSelectorEventLoop(selector_events.BaseSelectorEventLoop): | ||
fut.set_result(total_sent) | ||
return | ||
|
||
+ # On 32-bit architectures truncate to 1GiB to avoid OverflowError, | ||
+ # see bpo-38319. | ||
+ if sys.maxsize < 2 ** 32: | ||
+ blocksize = min(blocksize, 2 ** 30) | ||
+ | ||
try: | ||
sent = os.sendfile(fd, fileno, offset, blocksize) | ||
diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py | ||
index f34a5b4b44..b1d0f1e61e 100644 | ||
--- a/Lib/asyncio/unix_events.py | ||
+++ b/Lib/asyncio/unix_events.py | ||
@@ -369,6 +369,11 @@ class _UnixSelectorEventLoop(selector_events.BaseSelectorEventLoop): | ||
fut.set_result(total_sent) | ||
return | ||
|
||
+ # On 32-bit architectures truncate to 1GiB to avoid OverflowError, | ||
+ # see bpo-38319. | ||
+ if sys.maxsize < 2 ** 32: | ||
+ blocksize = min(blocksize, 2 ** 30) | ||
+ | ||
try: | ||
sent = os.sendfile(fd, fileno, offset, blocksize) | ||
except (BlockingIOError, InterruptedError): |
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
113 changes: 113 additions & 0 deletions
113
python/3.12/gh-106527-asyncio-optimize-to-add-remove-readers-and.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,113 @@ | ||
From b7dc795dfd175c0d25a479cfaf94a13c368a5a7b Mon Sep 17 00:00:00 2001 | ||
From: "J. Nick Koston" <nick@koston.org> | ||
Date: Sat, 22 Jul 2023 16:07:40 -0500 | ||
Subject: [PATCH] gh-106527: asyncio: optimize to add/remove readers and | ||
writers (#106528) | ||
|
||
--- | ||
Lib/asyncio/selector_events.py | 64 +++++++++---------- | ||
Lib/test/test_asyncio/test_selector_events.py | 36 +++++------ | ||
2 files changed, 47 insertions(+), 53 deletions(-) | ||
|
||
diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py | ||
index f895750e3c..d521b4e2e2 100644 | ||
--- a/Lib/asyncio/selector_events.py | ||
+++ b/Lib/asyncio/selector_events.py | ||
@@ -274,9 +274,8 @@ def _ensure_fd_no_transport(self, fd): | ||
def _add_reader(self, fd, callback, *args): | ||
self._check_closed() | ||
handle = events.Handle(callback, args, self, None) | ||
- try: | ||
- key = self._selector.get_key(fd) | ||
- except KeyError: | ||
+ key = self._selector.get_map().get(fd) | ||
+ if key is None: | ||
self._selector.register(fd, selectors.EVENT_READ, | ||
(handle, None)) | ||
else: | ||
@@ -290,30 +289,27 @@ def _add_reader(self, fd, callback, *args): | ||
def _remove_reader(self, fd): | ||
if self.is_closed(): | ||
return False | ||
- try: | ||
- key = self._selector.get_key(fd) | ||
- except KeyError: | ||
+ key = self._selector.get_map().get(fd) | ||
+ if key is None: | ||
return False | ||
+ mask, (reader, writer) = key.events, key.data | ||
+ mask &= ~selectors.EVENT_READ | ||
+ if not mask: | ||
+ self._selector.unregister(fd) | ||
else: | ||
- mask, (reader, writer) = key.events, key.data | ||
- mask &= ~selectors.EVENT_READ | ||
- if not mask: | ||
- self._selector.unregister(fd) | ||
- else: | ||
- self._selector.modify(fd, mask, (None, writer)) | ||
+ self._selector.modify(fd, mask, (None, writer)) | ||
|
||
- if reader is not None: | ||
- reader.cancel() | ||
- return True | ||
- else: | ||
- return False | ||
+ if reader is not None: | ||
+ reader.cancel() | ||
+ return True | ||
+ else: | ||
+ return False | ||
|
||
def _add_writer(self, fd, callback, *args): | ||
self._check_closed() | ||
handle = events.Handle(callback, args, self, None) | ||
- try: | ||
- key = self._selector.get_key(fd) | ||
- except KeyError: | ||
+ key = self._selector.get_map().get(fd) | ||
+ if key is None: | ||
self._selector.register(fd, selectors.EVENT_WRITE, | ||
(None, handle)) | ||
else: | ||
@@ -328,24 +324,22 @@ def _remove_writer(self, fd): | ||
"""Remove a writer callback.""" | ||
if self.is_closed(): | ||
return False | ||
- try: | ||
- key = self._selector.get_key(fd) | ||
- except KeyError: | ||
+ key = self._selector.get_map().get(fd) | ||
+ if key is None: | ||
return False | ||
+ mask, (reader, writer) = key.events, key.data | ||
+ # Remove both writer and connector. | ||
+ mask &= ~selectors.EVENT_WRITE | ||
+ if not mask: | ||
+ self._selector.unregister(fd) | ||
else: | ||
- mask, (reader, writer) = key.events, key.data | ||
- # Remove both writer and connector. | ||
- mask &= ~selectors.EVENT_WRITE | ||
- if not mask: | ||
- self._selector.unregister(fd) | ||
- else: | ||
- self._selector.modify(fd, mask, (reader, None)) | ||
+ self._selector.modify(fd, mask, (reader, None)) | ||
|
||
- if writer is not None: | ||
- writer.cancel() | ||
- return True | ||
- else: | ||
- return False | ||
+ if writer is not None: | ||
+ writer.cancel() | ||
+ return True | ||
+ else: | ||
+ return False | ||
|
||
def add_reader(self, fd, callback, *args): | ||
"""Add a reader callback.""" | ||
-- | ||
2.39.2 (Apple Git-143) | ||
|
73 changes: 73 additions & 0 deletions
73
python/3.12/gh-106554-replace-_BaseSelectorImpl._key_from_fd-wit.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,73 @@ | ||
From aeef8591e41b68341af308e56a744396c66879cc Mon Sep 17 00:00:00 2001 | ||
From: "J. Nick Koston" <nick@koston.org> | ||
Date: Fri, 14 Jul 2023 08:46:30 -1000 | ||
Subject: [PATCH] gh-106554: replace `_BaseSelectorImpl._key_from_fd` with | ||
`dict.get` (#106555) | ||
|
||
--- | ||
Lib/selectors.py | 21 ++++----------------- | ||
1 file changed, 4 insertions(+), 17 deletions(-) | ||
|
||
diff --git a/Lib/selectors.py b/Lib/selectors.py | ||
index dfcc125dcd..6d82935445 100644 | ||
--- a/Lib/selectors.py | ||
+++ b/Lib/selectors.py | ||
@@ -276,19 +276,6 @@ def close(self): | ||
def get_map(self): | ||
return self._map | ||
|
||
- def _key_from_fd(self, fd): | ||
- """Return the key associated to a given file descriptor. | ||
- | ||
- Parameters: | ||
- fd -- file descriptor | ||
- | ||
- Returns: | ||
- corresponding key, or None if not found | ||
- """ | ||
- try: | ||
- return self._fd_to_key[fd] | ||
- except KeyError: | ||
- return None | ||
|
||
|
||
class SelectSelector(_BaseSelectorImpl): | ||
@@ -336,7 +323,7 @@ def select(self, timeout=None): | ||
if fd in w: | ||
events |= EVENT_WRITE | ||
|
||
- key = self._key_from_fd(fd) | ||
+ key = self._fd_to_key.get(fd) | ||
if key: | ||
ready.append((key, events & key.events)) | ||
return ready | ||
@@ -426,7 +413,7 @@ def select(self, timeout=None): | ||
if event & ~self._EVENT_WRITE: | ||
events |= EVENT_READ | ||
|
||
- key = self._key_from_fd(fd) | ||
+ key = self._fd_to_key.get(fd) | ||
if key: | ||
ready.append((key, events & key.events)) | ||
return ready | ||
@@ -479,7 +466,7 @@ def select(self, timeout=None): | ||
if event & ~select.EPOLLOUT: | ||
events |= EVENT_READ | ||
|
||
- key = self._key_from_fd(fd) | ||
+ key = self._fd_to_key.get(fd) | ||
if key: | ||
ready.append((key, events & key.events)) | ||
return ready | ||
@@ -574,7 +561,7 @@ def select(self, timeout=None): | ||
if flag == select.KQ_FILTER_WRITE: | ||
events |= EVENT_WRITE | ||
|
||
- key = self._key_from_fd(fd) | ||
+ key = self._fd_to_key.get(fd) | ||
if key: | ||
ready.append((key, events & key.events)) | ||
return ready | ||
-- | ||
2.39.2 (Apple Git-143) | ||
|
43 changes: 43 additions & 0 deletions
43
python/3.12/gh-106664-selectors-add-get-method-to-_SelectorMappi.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,43 @@ | ||
From 8d2f3c36caf9ecdee1176314b18388aef6e7f2c2 Mon Sep 17 00:00:00 2001 | ||
From: "J. Nick Koston" <nick@koston.org> | ||
Date: Thu, 13 Jul 2023 09:18:53 -1000 | ||
Subject: [PATCH] gh-106664: selectors: add get() method to _SelectorMapping | ||
(#106665) | ||
|
||
It can be used to avoid raising and catching KeyError twice via __getitem__. | ||
|
||
Co-authored-by: Inada Naoki <songofacandy@gmail.com> | ||
--- | ||
Lib/selectors.py | 14 +++++++++----- | ||
Lib/test/test_selectors.py | 6 ++++++ | ||
2 files changed, 15 insertions(+), 5 deletions(-) | ||
|
||
diff --git a/Lib/selectors.py b/Lib/selectors.py | ||
index af6a4f94b5..dfcc125dcd 100644 | ||
--- a/Lib/selectors.py | ||
+++ b/Lib/selectors.py | ||
@@ -66,12 +66,16 @@ def __init__(self, selector): | ||
def __len__(self): | ||
return len(self._selector._fd_to_key) | ||
|
||
+ def get(self, fileobj, default=None): | ||
+ fd = self._selector._fileobj_lookup(fileobj) | ||
+ return self._selector._fd_to_key.get(fd, default) | ||
+ | ||
def __getitem__(self, fileobj): | ||
- try: | ||
- fd = self._selector._fileobj_lookup(fileobj) | ||
- return self._selector._fd_to_key[fd] | ||
- except KeyError: | ||
- raise KeyError("{!r} is not registered".format(fileobj)) from None | ||
+ fd = self._selector._fileobj_lookup(fileobj) | ||
+ key = self._selector._fd_to_key.get(fd) | ||
+ if key is None: | ||
+ raise KeyError("{!r} is not registered".format(fileobj)) | ||
+ return key | ||
|
||
def __iter__(self): | ||
return iter(self._selector._fd_to_key) | ||
-- | ||
2.39.2 (Apple Git-143) | ||
|
57 changes: 57 additions & 0 deletions
57
python/3.12/gh-106751-selectors-optimize-EpollSelector.select-10.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,57 @@ | ||
From aecf6aca515a203a823a87c711f15cbb82097c8b Mon Sep 17 00:00:00 2001 | ||
From: "J. Nick Koston" <nick@koston.org> | ||
Date: Tue, 18 Jul 2023 00:16:32 -1000 | ||
Subject: [PATCH] gh-106751: selectors: optimize EpollSelector.select() | ||
(#106754) | ||
|
||
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com> | ||
--- | ||
Lib/selectors.py | 17 +++++++++-------- | ||
1 file changed, 9 insertions(+), 8 deletions(-) | ||
|
||
diff --git a/Lib/selectors.py b/Lib/selectors.py | ||
index 6d82935445..a42d156340 100644 | ||
--- a/Lib/selectors.py | ||
+++ b/Lib/selectors.py | ||
@@ -430,6 +430,9 @@ class PollSelector(_PollLikeSelector): | ||
|
||
if hasattr(select, 'epoll'): | ||
|
||
+ _NOT_EPOLLIN = ~select.EPOLLIN | ||
+ _NOT_EPOLLOUT = ~select.EPOLLOUT | ||
+ | ||
class EpollSelector(_PollLikeSelector): | ||
"""Epoll-based selector.""" | ||
_selector_cls = select.epoll | ||
@@ -452,22 +455,20 @@ def select(self, timeout=None): | ||
# epoll_wait() expects `maxevents` to be greater than zero; | ||
# we want to make sure that `select()` can be called when no | ||
# FD is registered. | ||
- max_ev = max(len(self._fd_to_key), 1) | ||
+ max_ev = len(self._fd_to_key) or 1 | ||
|
||
ready = [] | ||
try: | ||
fd_event_list = self._selector.poll(timeout, max_ev) | ||
except InterruptedError: | ||
return ready | ||
- for fd, event in fd_event_list: | ||
- events = 0 | ||
- if event & ~select.EPOLLIN: | ||
- events |= EVENT_WRITE | ||
- if event & ~select.EPOLLOUT: | ||
- events |= EVENT_READ | ||
|
||
- key = self._fd_to_key.get(fd) | ||
+ fd_to_key = self._fd_to_key | ||
+ for fd, event in fd_event_list: | ||
+ key = fd_to_key.get(fd) | ||
if key: | ||
+ events = ((event & _NOT_EPOLLIN and EVENT_WRITE) | ||
+ | (event & _NOT_EPOLLOUT and EVENT_READ)) | ||
ready.append((key, events & key.events)) | ||
return ready | ||
|
||
-- | ||
2.39.2 (Apple Git-143) | ||
|
File renamed without changes.
Oops, something went wrong.