Skip to content
Merged
Changes from all commits
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
9 changes: 3 additions & 6 deletions Lib/test/test_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ def test_current_exceptions(self):
# Spawn a thread that blocks at a known place. Then the main
# thread does sys._current_frames(), and verifies that the frames
# returned make sense.
entered_g = threading.Event()
g_raised = threading.Event()
leave_g = threading.Event()
thread_info = [] # the thread's id

Expand All @@ -520,22 +520,19 @@ def f123():

def g456():
thread_info.append(threading.get_ident())
entered_g.set()
while True:
try:
raise ValueError("oops")
except ValueError:
g_raised.set()
if leave_g.wait(timeout=support.LONG_TIMEOUT):
break

t = threading.Thread(target=f123)
t.start()
entered_g.wait()
g_raised.wait(timeout=support.LONG_TIMEOUT)
Copy link
Member Author

@FFY00 FFY00 Oct 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also added a timeout here, as if an unexpected exception is raised in the thread, the event will never be set, and we will deadlock.


try:
# 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
# to its leave_g.wait().
self.assertEqual(len(thread_info), 1)
thread_id = thread_info[0]

Expand Down