Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Make sure that tight loop interruption test terminates eventually.
  • Loading branch information
markshannon committed Jul 17, 2021
commit 413dffd117baee6fda798965cfdb23c4d37b14ad
28 changes: 17 additions & 11 deletions Lib/test/test_threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -1606,22 +1606,28 @@ def test_interrupt_main_invalid_signal(self):

@threading_helper.reap_threads
def test_can_interrupt_tight_loops(self):
#Nothing to assert here. It just shouldn't hang.

cont = True
started = False
def worker():
nonlocal started
started = True
while cont:
cont = [True]
started = [False]
interrupted = [False]

def worker(started, cont, interrupted):
iterations = 100_000_000
started[0] = True
while cont[0]:
if iterations:
iterations -= 1
else:
return
pass
interrupted[0] = True

t = threading.Thread(target=worker)
t = threading.Thread(target=worker,args=(started, cont, interrupted))
t.start()
while not started:
while not started[0]:
pass
cont = False
cont[0] = False
t.join()
self.assertTrue(interrupted[0])


class AtexitTests(unittest.TestCase):
Expand Down