diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2017-09-14 21:40:56 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-14 21:40:56 (GMT) |
commit | b9b69003d91c6ea94b890ce24ed25686d30f1428 (patch) | |
tree | 51ff0c32353a7f82e02879bd7b8efd36ffc17ca9 /Lib/test/support/__init__.py | |
parent | 167cbde50a88ec2a7d26b2cb9891d5e32bdfbfb5 (diff) | |
download | cpython-b9b69003d91c6ea94b890ce24ed25686d30f1428.zip cpython-b9b69003d91c6ea94b890ce24ed25686d30f1428.tar.gz cpython-b9b69003d91c6ea94b890ce24ed25686d30f1428.tar.bz2 |
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.
Diffstat (limited to 'Lib/test/support/__init__.py')
-rw-r--r-- | Lib/test/support/__init__.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index 63f7a91..b2e4560 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -2107,6 +2107,16 @@ def wait_threads_exit(timeout=60.0): gc_collect() +def join_thread(thread, timeout=30.0): + """Join a thread. Raise an AssertionError if the thread is still alive + after timeout seconds. + """ + thread.join(timeout) + if thread.is_alive(): + msg = f"failed to join the thread in {timeout:.1f} seconds" + raise AssertionError(msg) + + def reap_children(): """Use this function at the end of test_main() whenever sub-processes are started. This will help ensure that no extra children (zombies) |