Skip to content

Commit 2bf4d51

Browse files
ambvclaude
andcommitted
Collect concurrent-test failures in the main thread
Exceptions raised in worker threads don't propagate to the unittest result, so report weakref mismatches via a shared list instead. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 7d20607 commit 2bf4d51

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

Lib/test/test_frame.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,19 +440,25 @@ def gen():
440440
g = gen()
441441
frame = next(g)
442442
barrier = threading.Barrier(4)
443+
# Collect failures instead of asserting in the workers: exceptions
444+
# raised in threads don't propagate to the unittest result.
445+
failures = []
443446
def work():
444447
barrier.wait()
445448
for _ in range(1000):
446449
ref = weakref.ref(frame)
447-
self.assertIs(ref(), frame)
450+
if ref() is not frame:
451+
failures.append('shared ref dead while frame alive')
448452
# Callback refs are not shared, so this concurrently adds
449453
# to and removes from the frame's weakref list.
450454
cb_ref = weakref.ref(frame, lambda r: None)
451-
self.assertIs(cb_ref(), frame)
455+
if cb_ref() is not frame:
456+
failures.append('callback ref dead while frame alive')
452457
del ref, cb_ref
453458
threads = [threading.Thread(target=work) for _ in range(4)]
454459
with threading_helper.start_threads(threads):
455460
pass
461+
self.assertEqual(failures, [])
456462
ref = weakref.ref(frame)
457463
del frame
458464
g.close()

0 commit comments

Comments
 (0)