10000 [3.10] bpo-44645: Check for interrupts on any potentially backwards e… · python/cpython@0e349ea · GitHub
[go: up one dir, main page]

Skip to content

Commit 0e349ea

Browse files
authored
[3.10] bpo-44645: Check for interrupts on any potentially backwards edge. (GH-27167) (GH-27183)
(cherry picked from commit 000e70a) Co-authored-by: Mark Shannon <mark@hotpy.org>
1 parent 7059880 commit 0e349ea

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

Lib/test/test_threading.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,6 +1604,31 @@ def test_interrupt_main_invalid_signal(self):
16041604
self.assertRaises(ValueError, _thread.interrupt_main, signal.NSIG)
16051605
self.assertRaises(ValueError, _thread.interrupt_main, 1000000)
16061606

1607+
@threading_helper.reap_threads
1608+
def test_can_interrupt_tight_loops(self):
1609+
cont = True
1610+
started = False
1611+
iterations = 100_000_000
1612+
1613+
def worker():
1614+
nonlocal iterations
1615+
nonlocal started
1616+
started = True
1617+
while cont:
1618+
if iterations:
1619+
iterations -= 1
1620+
else:
1621+
return
1622+
pass
1623+
1624+
t = threading.Thread(target=worker)
1625+
t.start()
1626+
while not started:
1627+
pass
1628+
cont = False
1629+
t.join()
1630+
self.assertNotEqual(iterations, 0)
1631+
16071632

16081633
class AtexitTests(unittest.TestCase):
16091634

Python/ceval.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3759,14 +3759,17 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
37593759
if (Py_IsFalse(cond)) {
37603760
Py_DECREF(cond);
37613761
JUMPTO(oparg);
3762+
CHECK_EVAL_BREAKER();
37623763
DISPATCH();
37633764
}
37643765
err = PyObject_IsTrue(cond);
37653766
Py_DECREF(cond);
37663767
if (err > 0)
37673768
;
3768-
else if (err == 0)
3769+
else if (err == 0) {
37693770
JUMPTO(oparg);
3771+
CHECK_EVAL_BREAKER();
3772+
}
37703773
else
37713774
goto error;
37723775
DISPATCH();
@@ -3783,12 +3786,14 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
37833786
if (Py_IsTrue(cond)) {
37843787
Py_DECREF(cond);
37853788
JUMPTO(oparg);
3789+
CHECK_EVAL_BREAKER();
37863790
DISPATCH();
37873791
}
37883792
err = PyObject_IsTrue(cond);
37893793
Py_DECREF(cond);
37903794
if (err > 0) {
37913795
JUMPTO(oparg);
3796+
CHECK_EVAL_BREAKER();
37923797
}
37933798
else if (err == 0)
37943799
;

0 commit comments

Comments
 (0)
0