Skip to content

Commit 7d1d912

Browse files
committed
Check for interrupts on any backwards edge.
1 parent 4cb7263 commit 7d1d912

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

Lib/test/test_threading.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,6 +1604,20 @@ 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+
def test_can_interrupt_tight_loops(self):
1608+
#Nothing to assert here. It just shouldn't hang.
1609+
1610+
cont = True
1611+
def worker():
1612+
while cont:
1613+
pass
1614+
1615+
t = threading.Thread(target=worker)
1616+
t.start()
1617+
time.sleep(0.1)
1618+
cont = False
1619+
t.join()
1620+
16071621

16081622
class AtexitTests(unittest.TestCase):
16091623

Python/ceval.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3638,14 +3638,17 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
36383638
if (Py_IsFalse(cond)) {
36393639
Py_DECREF(cond);
36403640
JUMPTO(oparg);
3641+
CHECK_EVAL_BREAKER();
36413642
DISPATCH();
36423643
}
36433644
err = PyObject_IsTrue(cond);
36443645
Py_DECREF(cond);
36453646
if (err > 0)
36463647
;
3647-
else if (err == 0)
3648+
else if (err == 0) {
36483649
JUMPTO(oparg);
3650+
CHECK_EVAL_BREAKER();
3651+
}
36493652
else
36503653
goto error;
36513654
DISPATCH();
@@ -3662,12 +3665,14 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
36623665
if (Py_IsTrue(cond)) {
36633666
Py_DECREF(cond);
36643667
JUMPTO(oparg);
3668+
CHECK_EVAL_BREAKER();
36653669
DISPATCH();
36663670
}
36673671
err = PyObject_IsTrue(cond);
36683672
Py_DECREF(cond);
36693673
if (err > 0) {
36703674
JUMPTO(oparg);
3675+
CHECK_EVAL_BREAKER();
36713676
}
36723677
else if (err == 0)
36733678
;

0 commit comments

Comments
 (0)