diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2017-09-14 20:07:24 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-14 20:07:24 (GMT) |
commit | ff40ecda73178dfcad24e26240d684356ef20793 (patch) | |
tree | 0533f9354f838a97a67fc22749b1b1b7374691fb /Lib/test/test_threading.py | |
parent | b8c7be2c523b012e57915182543d06657161057f (diff) | |
download | cpython-ff40ecda73178dfcad24e26240d684356ef20793.zip cpython-ff40ecda73178dfcad24e26240d684356ef20793.tar.gz cpython-ff40ecda73178dfcad24e26240d684356ef20793.tar.bz2 |
bpo-31234: Add test.support.wait_threads_exit() (#3578)
Use _thread.count() to wait until threads exit. The new context
manager prevents the "dangling thread" warning.
Diffstat (limited to 'Lib/test/test_threading.py')
-rw-r--r-- | Lib/test/test_threading.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py index ab383c2..af6796c 100644 --- a/Lib/test/test_threading.py +++ b/Lib/test/test_threading.py @@ -125,9 +125,10 @@ class ThreadTests(BaseTestCase): done.set() done = threading.Event() ident = [] - _thread.start_new_thread(f, ()) - done.wait() - self.assertIsNotNone(ident[0]) + with support.wait_threads_exit(): + tid = _thread.start_new_thread(f, ()) + done.wait() + self.assertEqual(ident[0], tid) # Kill the "immortal" _DummyThread del threading._active[ident[0]] @@ -165,9 +166,10 @@ class ThreadTests(BaseTestCase): mutex = threading.Lock() mutex.acquire() - tid = _thread.start_new_thread(f, (mutex,)) - # Wait for the thread to finish. - mutex.acquire() + with support.wait_threads_exit(): + tid = _thread.start_new_thread(f, (mutex,)) + # Wait for the thread to finish. + mutex.acquire() self.assertIn(tid, threading._active) self.assertIsInstance(threading._active[tid], threading._DummyThread) #Issue 29376 |