diff options
author | Victor Stinner <vstinner@redhat.com> | 2018-06-01 13:51:02 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-01 13:51:02 (GMT) |
commit | 5dbb48aaac0ff74648b355ebdde222856004b1ef (patch) | |
tree | c47bd93d6333eb31b1461d75c5463ef058d666b2 /Lib/test/test_threading.py | |
parent | 95681c7a7ddd436ba7d6c10d1202c33dd6bd648b (diff) | |
download | cpython-5dbb48aaac0ff74648b355ebdde222856004b1ef.zip cpython-5dbb48aaac0ff74648b355ebdde222856004b1ef.tar.gz cpython-5dbb48aaac0ff74648b355ebdde222856004b1ef.tar.bz2 |
[3.6] bpo-31234: Add test.support.wait_threads_exit() (GH-3578) (GH-7315)
* bpo-31234: Add test.support.wait_threads_exit() (GH-3578)
Use _thread.count() to wait until threads exit. The new context
manager prevents the "dangling thread" warning.
(cherry picked from commit ff40ecda73178dfcad24e26240d684356ef20793)
* bpo-31234: Try to fix lock_tests warning (#3557)
Try to fix the "Warning -- threading_cleanup() failed to cleanup 1
threads" warning in test.lock_tests: wait a little bit longer to give
time to the threads to complete.
Warning seen on test_thread and test_importlib.
(cherry picked from commit 096ae3373abac2c8b3a26a3fe33cc8bd4cbccd4e)
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 b42314f..43ef22b 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 |