diff --git a/backport-bpo-20369-concurrent.futures.wait-now-deduplicates-f.patch b/backport-bpo-20369-concurrent.futures.wait-now-deduplicates-f.patch new file mode 100644 index 0000000000000000000000000000000000000000..aaac19e4538e9f2b1bbb6bd657664ad2a07f1b88 --- /dev/null +++ b/backport-bpo-20369-concurrent.futures.wait-now-deduplicates-f.patch @@ -0,0 +1,102 @@ +From 9a9061d1ca7e28dc2b7e326153e933872c7cd452 Mon Sep 17 00:00:00 2001 +From: "Miss Islington (bot)" + <31488909+miss-islington@users.noreply.github.com> +Date: Tue, 4 Jan 2022 06:27:26 -0800 +Subject: [PATCH] =?UTF-8?q?bpo-20369:=20concurrent.futures.wait()=20now=20?= + =?UTF-8?q?deduplicates=20futures=20given=20a=E2=80=A6=20(GH-30168)?= +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +* bpo-20369: concurrent.futures.wait() now deduplicates futures given as arg. + +* 📜🤖 Added by blurb_it. + +Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> +(cherry picked from commit 7d7817cf0f826e566d8370a0e974bbfed6611d91) + +Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> +--- + Doc/library/concurrent.futures.rst | 3 ++- + Lib/concurrent/futures/_base.py | 13 +++++++------ + Lib/test/test_concurrent_futures.py | 8 ++++++++ + .../next/Library/2021-12-17-12-06-40.bpo-20369.zzLuBz.rst | 1 + + 4 files changed, 18 insertions(+), 7 deletions(-) + create mode 100644 Misc/NEWS.d/next/Library/2021-12-17-12-06-40.bpo-20369.zzLuBz.rst + +diff --git a/Doc/library/concurrent.futures.rst b/Doc/library/concurrent.futures.rst +index 897efc2..f62b5e3 100644 +--- a/Doc/library/concurrent.futures.rst ++++ b/Doc/library/concurrent.futures.rst +@@ -435,7 +435,8 @@ Module Functions + .. function:: wait(fs, timeout=None, return_when=ALL_COMPLETED) + + Wait for the :class:`Future` instances (possibly created by different +- :class:`Executor` instances) given by *fs* to complete. Returns a named ++ :class:`Executor` instances) given by *fs* to complete. Duplicate futures ++ given to *fs* are removed and will be returned only once. Returns a named + 2-tuple of sets. The first set, named ``done``, contains the futures that + completed (finished or cancelled futures) before the wait completed. The + second set, named ``not_done``, contains the futures that did not complete +diff --git a/Lib/concurrent/futures/_base.py b/Lib/concurrent/futures/_base.py +index 6095026..5c00f2e 100644 +--- a/Lib/concurrent/futures/_base.py ++++ b/Lib/concurrent/futures/_base.py +@@ -284,13 +284,14 @@ def wait(fs, timeout=None, return_when=ALL_COMPLETED): + A named 2-tuple of sets. The first set, named 'done', contains the + futures that completed (is finished or cancelled) before the wait + completed. The second set, named 'not_done', contains uncompleted +- futures. ++ futures. Duplicate futures given to *fs* are removed and will be ++ returned only once. + """ ++ fs = set(fs) + with _AcquireFutures(fs): +- done = set(f for f in fs +- if f._state in [CANCELLED_AND_NOTIFIED, FINISHED]) +- not_done = set(fs) - done +- ++ done = {f for f in fs ++ if f._state in [CANCELLED_AND_NOTIFIED, FINISHED]} ++ not_done = fs - done + if (return_when == FIRST_COMPLETED) and done: + return DoneAndNotDoneFutures(done, not_done) + elif (return_when == FIRST_EXCEPTION) and done: +@@ -309,7 +310,7 @@ def wait(fs, timeout=None, return_when=ALL_COMPLETED): + f._waiters.remove(waiter) + + done.update(waiter.finished_futures) +- return DoneAndNotDoneFutures(done, set(fs) - done) ++ return DoneAndNotDoneFutures(done, fs - done) + + class Future(object): + """Represents the result of an asynchronous computation.""" +diff --git a/Lib/test/test_concurrent_futures.py b/Lib/test/test_concurrent_futures.py +index 48d56d9..d693fb4 100644 +--- a/Lib/test/test_concurrent_futures.py ++++ b/Lib/test/test_concurrent_futures.py +@@ -564,6 +564,14 @@ create_executor_tests(ProcessPoolShutdownTest, + + + class WaitTests: ++ def test_20369(self): ++ # See https://bugs.python.org/issue20369 ++ future = self.executor.submit(time.sleep, 1.5) ++ done, not_done = futures.wait([future, future], ++ return_when=futures.ALL_COMPLETED) ++ self.assertEqual({future}, done) ++ self.assertEqual(set(), not_done) ++ + + def test_first_completed(self): + future1 = self.executor.submit(mul, 21, 2) +diff --git a/Misc/NEWS.d/next/Library/2021-12-17-12-06-40.bpo-20369.zzLuBz.rst b/Misc/NEWS.d/next/Library/2021-12-17-12-06-40.bpo-20369.zzLuBz.rst +new file mode 100644 +index 0000000..cc5cd00 +--- /dev/null ++++ b/Misc/NEWS.d/next/Library/2021-12-17-12-06-40.bpo-20369.zzLuBz.rst +@@ -0,0 +1 @@ ++:func:`concurrent.futures.wait` no longer blocks forever when given duplicate Futures. Patch by Kumar Aditya. +-- +1.8.3.1 + diff --git a/backport-bpo-43498-Fix-dictionary-iteration-error-in-_Executo.patch b/backport-bpo-43498-Fix-dictionary-iteration-error-in-_Executo.patch new file mode 100644 index 0000000000000000000000000000000000000000..b89780f6364a944917d2bd41150c5d952b0dadf5 --- /dev/null +++ b/backport-bpo-43498-Fix-dictionary-iteration-error-in-_Executo.patch @@ -0,0 +1,43 @@ +From 3b9d886567c4fc6279c2198b6711f0590dbf3336 Mon Sep 17 00:00:00 2001 +From: "Miss Islington (bot)" + <31488909+miss-islington@users.noreply.github.com> +Date: Mon, 29 Nov 2021 04:28:46 -0800 +Subject: [PATCH] bpo-43498: Fix dictionary iteration error in + _ExecutorManagerThread (GH-24868) +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +(cherry picked from commit 7431448b817d3bf87f71661cf8f3d537807ab2e2) + +Co-authored-by: Jakub Kulík +--- + Lib/concurrent/futures/process.py | 2 +- + Misc/NEWS.d/next/Library/2021-04-20-14-14-16.bpo-43498.L_Hq-8.rst | 2 ++ + 2 files changed, 3 insertions(+), 1 deletion(-) + create mode 100644 Misc/NEWS.d/next/Library/2021-04-20-14-14-16.bpo-43498.L_Hq-8.rst + +diff --git a/Lib/concurrent/futures/process.py b/Lib/concurrent/futures/process.py +index 90bc98b..a29e524 100644 +--- a/Lib/concurrent/futures/process.py ++++ b/Lib/concurrent/futures/process.py +@@ -373,7 +373,7 @@ class _ExecutorManagerThread(threading.Thread): + assert not self.thread_wakeup._closed + wakeup_reader = self.thread_wakeup._reader + readers = [result_reader, wakeup_reader] +- worker_sentinels = [p.sentinel for p in self.processes.values()] ++ worker_sentinels = [p.sentinel for p in list(self.processes.values())] + ready = mp.connection.wait(readers + worker_sentinels) + + cause = None +diff --git a/Misc/NEWS.d/next/Library/2021-04-20-14-14-16.bpo-43498.L_Hq-8.rst b/Misc/NEWS.d/next/Library/2021-04-20-14-14-16.bpo-43498.L_Hq-8.rst +new file mode 100644 +index 0000000..4713d14 +--- /dev/null ++++ b/Misc/NEWS.d/next/Library/2021-04-20-14-14-16.bpo-43498.L_Hq-8.rst +@@ -0,0 +1,2 @@ ++Avoid a possible *"RuntimeError: dictionary changed size during iteration"* ++when adjusting the process count of :class:`ProcessPoolExecutor`. +-- +1.8.3.1 + diff --git a/python3.spec b/python3.spec index 1a7443585e724c1341b8ed366100234d4e460378..ba64c121a7ee8c77203b99a94f96ad32040db42f 100644 --- a/python3.spec +++ b/python3.spec @@ -3,7 +3,7 @@ Summary: Interpreter of the Python3 programming language URL: https://www.python.org/ Version: 3.9.9 -Release: 4 +Release: 5 License: Python %global branchversion 3.9 @@ -91,6 +91,8 @@ Patch178: 00178-dont-duplicate-flags-in-sysconfig.patch Patch205: 00205-make-libpl-respect-lib64.patch Patch251: 00251-change-user-install-location.patch Patch6000: backport-Add--with-wheel-pkg-dir-configure-option.patch +Patch6001: backport-bpo-43498-Fix-dictionary-iteration-error-in-_Executo.patch +Patch6002: backport-bpo-20369-concurrent.futures.wait-now-deduplicates-f.patch Patch9000: add-the-sm3-method-for-obtaining-the-salt-value.patch @@ -179,6 +181,8 @@ rm -r Modules/expat %patch205 -p1 %patch251 -p1 %patch6000 -p1 +%patch6001 -p1 +%patch6002 -p1 %patch9000 -p1 @@ -795,6 +799,13 @@ export BEP_GTDLIST="$BEP_GTDLIST_TMP" %{_mandir}/*/* %changelog +* Thu Mar 03 2022 shixuantong - 3.9.9-5 +- Type:bugfix +- CVE:NA +- SUG:NA +- DESC:Fix dictionary iteration error in _ExecutorManagerThread + concurrent.futures.wait no longer blocks forever when given duplicate Futures + * Thu Feb 10 2022 shixuantong - 3.9.9-4 - Type:bugfix - CVE:NA