Fix deadlock on shutdown if test_current_{exception,frames} fails (#102019)
* Don't deadlock on shutdown if test_current_{exception,frames} fails These tests spawn a thread that waits on a threading.Event. If the test fails any of its assertions, the Event won't be signaled and the thread will wait indefinitely, causing a deadlock when threading._shutdown() tries to join all outstanding threads. Co-authored-by: Brett Simmers <bsimmers@meta.com> * Add a news entry * Fix whitespace --------- Co-authored-by: Brett Simmers <bsimmers@meta.com> Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
This commit is contained in:
parent
ccd98a3146
commit
0c857865e4
@ -445,6 +445,7 @@ class SysModuleTest(unittest.TestCase):
|
|||||||
t.start()
|
t.start()
|
||||||
entered_g.wait()
|
entered_g.wait()
|
||||||
|
|
||||||
|
try:
|
||||||
# At this point, t has finished its entered_g.set(), although it's
|
# At this point, t has finished its entered_g.set(), although it's
|
||||||
# impossible to guess whether it's still on that line or has moved on
|
# impossible to guess whether it's still on that line or has moved on
|
||||||
# to its leave_g.wait().
|
# to its leave_g.wait().
|
||||||
@ -481,7 +482,7 @@ class SysModuleTest(unittest.TestCase):
|
|||||||
filename, lineno, funcname, sourceline = stack[i+1]
|
filename, lineno, funcname, sourceline = stack[i+1]
|
||||||
self.assertEqual(funcname, "g456")
|
self.assertEqual(funcname, "g456")
|
||||||
self.assertIn(sourceline, ["leave_g.wait()", "entered_g.set()"])
|
self.assertIn(sourceline, ["leave_g.wait()", "entered_g.set()"])
|
||||||
|
finally:
|
||||||
# Reap the spawned thread.
|
# Reap the spawned thread.
|
||||||
leave_g.set()
|
leave_g.set()
|
||||||
t.join()
|
t.join()
|
||||||
@ -516,6 +517,7 @@ class SysModuleTest(unittest.TestCase):
|
|||||||
t.start()
|
t.start()
|
||||||
entered_g.wait()
|
entered_g.wait()
|
||||||
|
|
||||||
|
try:
|
||||||
# At this point, t has finished its entered_g.set(), although it's
|
# At this point, t has finished its entered_g.set(), although it's
|
||||||
# impossible to guess whether it's still on that line or has moved on
|
# impossible to guess whether it's still on that line or has moved on
|
||||||
# to its leave_g.wait().
|
# to its leave_g.wait().
|
||||||
@ -549,7 +551,7 @@ class SysModuleTest(unittest.TestCase):
|
|||||||
filename, lineno, funcname, sourceline = stack[i+1]
|
filename, lineno, funcname, sourceline = stack[i+1]
|
||||||
self.assertEqual(funcname, "g456")
|
self.assertEqual(funcname, "g456")
|
||||||
self.assertTrue(sourceline.startswith("if leave_g.wait("))
|
self.assertTrue(sourceline.startswith("if leave_g.wait("))
|
||||||
|
finally:
|
||||||
# Reap the spawned thread.
|
# Reap the spawned thread.
|
||||||
leave_g.set()
|
leave_g.set()
|
||||||
t.join()
|
t.join()
|
||||||
|
@ -0,0 +1,2 @@
|
|||||||
|
Fix deadlock on shutdown if ``test_current_{exception,frames}`` fails. Patch
|
||||||
|
by Jacob Bower.
|
Loading…
x
Reference in New Issue
Block a user