mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-31234: Add support.join_thread() helper (#3587)
join_thread() joins a thread but raises an AssertionError if the thread is still alive after timeout seconds.
This commit is contained in:
parent
167cbde50a
commit
b9b69003d9
9 changed files with 50 additions and 65 deletions
|
@ -3,6 +3,7 @@ import sched
|
|||
import threading
|
||||
import time
|
||||
import unittest
|
||||
from test import support
|
||||
|
||||
|
||||
TIMEOUT = 10
|
||||
|
@ -81,8 +82,7 @@ class TestCase(unittest.TestCase):
|
|||
self.assertEqual(q.get(timeout=TIMEOUT), 5)
|
||||
self.assertTrue(q.empty())
|
||||
timer.advance(1000)
|
||||
t.join(timeout=TIMEOUT)
|
||||
self.assertFalse(t.is_alive())
|
||||
support.join_thread(t, timeout=TIMEOUT)
|
||||
self.assertTrue(q.empty())
|
||||
self.assertEqual(timer.time(), 5)
|
||||
|
||||
|
@ -137,8 +137,7 @@ class TestCase(unittest.TestCase):
|
|||
self.assertEqual(q.get(timeout=TIMEOUT), 4)
|
||||
self.assertTrue(q.empty())
|
||||
timer.advance(1000)
|
||||
t.join(timeout=TIMEOUT)
|
||||
self.assertFalse(t.is_alive())
|
||||
support.join_thread(t, timeout=TIMEOUT)
|
||||
self.assertTrue(q.empty())
|
||||
self.assertEqual(timer.time(), 4)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue