@@ -838,18 +838,6 @@ The :mod:`test.support` module defines the following functions:
838838 .. versionadded :: 3.9
839839
840840
841- .. function :: wait_threads_exit(timeout=60.0)
842-
843- Context manager to wait until all threads created in the ``with `` statement
844- exit.
845-
846-
847- .. function :: start_threads(threads, unlock=None)
848-
849- Context manager to start *threads *. It attempts to join the threads upon
850- exit.
851-
852-
853841.. function :: calcobjsize(fmt)
854842
855843 Return :func: `struct.calcsize ` for ``nP{fmt}0n `` or, if ``gettotalrefcount ``
@@ -988,11 +976,6 @@ The :mod:`test.support` module defines the following functions:
988976 the trace function.
989977
990978
991- .. decorator :: reap_threads(func)
992-
993- Decorator to ensure the threads are cleaned up even if the test fails.
994-
995-
996979.. decorator :: bigmemtest(size, memuse, dry_run=True)
997980
998981 Decorator for bigmem tests.
@@ -1110,23 +1093,6 @@ The :mod:`test.support` module defines the following functions:
11101093 preserve internal cache.
11111094
11121095
1113- .. function :: threading_setup()
1114-
1115- Return current thread count and copy of dangling threads.
1116-
1117-
1118- .. function :: threading_cleanup(*original_values)
1119-
1120- Cleanup up threads not specified in *original_values *. Designed to emit
1121- a warning if a test leaves running threads in the background.
1122-
1123-
1124- .. function :: join_thread(thread, timeout=30.0)
1125-
1126- Join a *thread * within *timeout *. Raise an :exc: `AssertionError ` if thread
1127- is still alive after *timeout * seconds.
1128-
1129-
11301096.. function :: reap_children()
11311097
11321098 Use this at the end of ``test_main `` whenever sub-processes are started.
@@ -1140,39 +1106,6 @@ The :mod:`test.support` module defines the following functions:
11401106 is raised.
11411107
11421108
1143- .. function :: catch_threading_exception()
1144-
1145- Context manager catching :class: `threading.Thread ` exception using
1146- :func: `threading.excepthook `.
1147-
1148- Attributes set when an exception is catched:
1149-
1150- * ``exc_type ``
1151- * ``exc_value ``
1152- * ``exc_traceback ``
1153- * ``thread ``
1154-
1155- See :func: `threading.excepthook ` documentation.
1156-
1157- These attributes are deleted at the context manager exit.
1158-
1159- Usage::
1160-
1161- with support.catch_threading_exception() as cm:
1162- # code spawning a thread which raises an exception
1163- ...
1164-
1165- # check the thread exception, use cm attributes:
1166- # exc_type, exc_value, exc_traceback, thread
1167- ...
1168-
1169- # exc_type, exc_value, exc_traceback, thread attributes of cm no longer
1170- # exists at this point
1171- # (to avoid reference cycles)
1172-
1173- .. versionadded :: 3.8
1174-
1175-
11761109.. function :: catch_unraisable_exception()
11771110
11781111 Context manager catching unraisable exception using
@@ -1628,3 +1561,81 @@ The module defines the following class:
16281561.. method :: BytecodeTestCase.assertNotInBytecode(x, opname, argval=_UNSPECIFIED)
16291562
16301563 Throws :exc: `AssertionError ` if *opname * is found.
1564+
1565+
1566+ :mod: `test.support.threading_helper ` --- Utilities for threading tests
1567+ ======================================================================
1568+
1569+ .. module :: test.support.threading_helper
1570+ :synopsis: Support for threading tests.
1571+
1572+ The :mod: `test.support.threading_helper ` module provides support for threading tests.
1573+
1574+ .. versionadded :: 3.10
1575+
1576+
1577+ .. function :: join_thread(thread, timeout=None)
1578+
1579+ Join a *thread * within *timeout *. Raise an :exc: `AssertionError ` if thread
1580+ is still alive after *timeout * seconds.
1581+
1582+
1583+ .. decorator :: reap_threads(func)
1584+
1585+ Decorator to ensure the threads are cleaned up even if the test fails.
1586+
1587+
1588+ .. function :: start_threads(threads, unlock=None)
1589+
1590+ Context manager to start *threads *. It attempts to join the threads upon
1591+ exit.
1592+
1593+
1594+ .. function :: threading_cleanup(*original_values)
1595+
1596+ Cleanup up threads not specified in *original_values *. Designed to emit
1597+ a warning if a test leaves running threads in the background.
1598+
1599+
1600+ .. function :: threading_setup()
1601+
1602+ Return current thread count and copy of dangling threads.
1603+
1604+
1605+ .. function :: wait_threads_exit(timeout=None)
1606+
1607+ Context manager to wait until all threads created in the ``with `` statement
1608+ exit.
1609+
1610+
1611+ .. function :: catch_threading_exception()
1612+
1613+ Context manager catching :class: `threading.Thread ` exception using
1614+ :func: `threading.excepthook `.
1615+
1616+ Attributes set when an exception is catched:
1617+
1618+ * ``exc_type ``
1619+ * ``exc_value ``
1620+ * ``exc_traceback ``
1621+ * ``thread ``
1622+
1623+ See :func: `threading.excepthook ` documentation.
1624+
1625+ These attributes are deleted at the context manager exit.
1626+
1627+ Usage::
1628+
1629+ with threading_helper.catch_threading_exception() as cm:
1630+ # code spawning a thread which raises an exception
1631+ ...
1632+
1633+ # check the thread exception, use cm attributes:
1634+ # exc_type, exc_value, exc_traceback, thread
1635+ ...
1636+
1637+ # exc_type, exc_value, exc_traceback, thread attributes of cm no longer
1638+ # exists at this point
1639+ # (to avoid reference cycles)
1640+
1641+ .. versionadded :: 3.8
0 commit comments