Index: Lib/test/test_threadsignals.py =================================================================== --- Lib/test/test_threadsignals.py (revision 78648) +++ Lib/test/test_threadsignals.py (working copy) @@ -5,6 +5,7 @@ import signal import os import sys +import time from test.test_support import run_unittest if sys.platform[:3] in ('win', 'os2') or sys.platform=='riscos': @@ -40,6 +41,7 @@ and that they were run by the main thread. """ def test_signals(self): + previous_refs = sys.getrefcount(send_signals) signalled_all.acquire() self.spawnSignallingThread() signalled_all.acquire() @@ -62,6 +64,11 @@ self.assertEqual( signal_blackboard[signal.SIGUSR2]['tripped_by'], thread.get_ident()) signalled_all.release() + # Wait until the thread ends, to prevent transient leaks + countdown = 9 + while countdown and sys.getrefcount(send_signals) > previous_refs: + countdown -= 1 + time.sleep(.01) def spawnSignallingThread(self): thread.start_new_thread(send_signals, ())