Skip to content

Commit 413dffd

Browse files
committed
Make sure that tight loop interruption test terminates eventually.
1 parent e52abd2 commit 413dffd

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

Lib/test/test_threading.py

+17-11
Original file line numberDiff line numberDiff line change
@@ -1606,22 +1606,28 @@ def test_interrupt_main_invalid_signal(self):
16061606

16071607
@threading_helper.reap_threads
16081608
def test_can_interrupt_tight_loops(self):
1609-
#Nothing to assert here. It just shouldn't hang.
1610-
1611-
cont = True
1612-
started = False
1613-
def worker():
1614-
nonlocal started
1615-
started = True
1616-
while cont:
1609+
cont = [True]
1610+
started = [False]
1611+
interrupted = [False]
1612+
1613+
def worker(started, cont, interrupted):
1614+
iterations = 100_000_000
1615+
started[0] = True
1616+
while cont[0]:
1617+
if iterations:
1618+
iterations -= 1
1619+
else:
1620+
return
16171621
pass
1622+
interrupted[0] = True
16181623

1619-
t = threading.Thread(target=worker)
1624+
t = threading.Thread(target=worker,args=(started, cont, interrupted))
16201625
t.start()
1621-
while not started:
1626+
while not started[0]:
16221627
pass
1623-
cont = False
1628+
cont[0] = False
16241629
t.join()
1630+
self.assertTrue(interrupted[0])
16251631

16261632

16271633
class AtexitTests(unittest.TestCase):

0 commit comments

Comments
 (0)