Skip to content

Commit c00b658

Browse files
authored
Merge branch 'main' into SE-notes
2 parents f83ffa8 + 24fa8f2 commit c00b658

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed

Doc/library/itertools.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,13 +1030,16 @@ The following recipes have a more mathematical flavor:
10301030
def sieve(n):
10311031
"Primes less than n."
10321032
# sieve(30) --> 2 3 5 7 11 13 17 19 23 29
1033+
if n > 2:
1034+
yield 2
1035+
start = 3
10331036
data = bytearray((0, 1)) * (n // 2)
1034-
data[:3] = 0, 0, 0
10351037
limit = math.isqrt(n) + 1
1036-
for p in compress(range(limit), data):
1038+
for p in iter_index(data, 1, start, limit):
1039+
yield from iter_index(data, 1, start, p*p)
10371040
data[p*p : n : p+p] = bytes(len(range(p*p, n, p+p)))
1038-
data[2] = 1
1039-
return iter_index(data, 1) if n > 2 else iter([])
1041+
start = p*p
1042+
yield from iter_index(data, 1, start)
10401043

10411044
def factor(n):
10421045
"Prime factors of n."

Lib/test/libregrtest/runtest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,12 @@ def iter_tests(self):
249249
else:
250250
yield from self.tests
251251

252+
@staticmethod
253+
def from_json_dict(json_dict):
254+
if json_dict['hunt_refleak']:
255+
json_dict['hunt_refleak'] = HuntRefleak(**json_dict['hunt_refleak'])
256+
return RunTests(**json_dict)
257+
252258

253259
# Minimum duration of a test to display its duration or to mention that
254260
# the test is running in background

Lib/test/libregrtest/runtest_mp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def default(self, o: Any) -> dict[str, Any]:
6868
def _decode_worker_job(d: dict[str, Any]) -> WorkerJob | dict[str, Any]:
6969
if "__worker_job__" in d:
7070
d.pop('__worker_job__')
71-
d['runtests'] = RunTests(**d['runtests'])
71+
d['runtests'] = RunTests.from_json_dict(d['runtests'])
7272
return WorkerJob(**d)
7373
if "__namespace__" in d:
7474
d.pop('__namespace__')

Lib/test/test_regrtest.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,12 +1018,16 @@ def test_run(self):
10181018
stats=TestStats(4, 1),
10191019
forever=True)
10201020

1021-
def check_leak(self, code, what):
1021+
def check_leak(self, code, what, *, multiprocessing=False):
10221022
test = self.create_test('huntrleaks', code=code)
10231023

10241024
filename = 'reflog.txt'
10251025
self.addCleanup(os_helper.unlink, filename)
1026-
output = self.run_tests('--huntrleaks', '6:3:', test,
1026+
cmd = ['--huntrleaks', '6:3:']
1027+
if multiprocessing:
1028+
cmd.append('-j1')
1029+
cmd.append(test)
1030+
output = self.run_tests(*cmd,
10271031
exitcode=EXITCODE_BAD_TEST,
10281032
stderr=subprocess.STDOUT)
10291033
self.check_executed_tests(output, [test], failed=test, stats=1)
@@ -1039,7 +1043,7 @@ def check_leak(self, code, what):
10391043
self.assertIn(line2, reflog)
10401044

10411045
@unittest.skipUnless(support.Py_DEBUG, 'need a debug build')
1042-
def test_huntrleaks(self):
1046+
def check_huntrleaks(self, *, multiprocessing: bool):
10431047
# test --huntrleaks
10441048
code = textwrap.dedent("""
10451049
import unittest
@@ -1050,7 +1054,13 @@ class RefLeakTest(unittest.TestCase):
10501054
def test_leak(self):
10511055
GLOBAL_LIST.append(object())
10521056
""")
1053-
self.check_leak(code, 'references')
1057+
self.check_leak(code, 'references', multiprocessing=multiprocessing)
1058+
1059+
def test_huntrleaks(self):
1060+
self.check_huntrleaks(multiprocessing=False)
1061+
1062+
def test_huntrleaks_mp(self):
1063+
self.check_huntrleaks(multiprocessing=True)
10541064

10551065
@unittest.skipUnless(support.Py_DEBUG, 'need a debug build')
10561066
def test_huntrleaks_fd_leak(self):

0 commit comments

Comments
 (0)