diff options
author | Steve Dower <steve.dower@python.org> | 2022-11-16 17:15:52 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-16 17:15:52 (GMT) |
commit | 19c1462e8dca3319c8290e2edcce482bd18cb018 (patch) | |
tree | 01d4d3189f912b0444faf55a44e34057e8dc5afb /Lib/test/audit-tests.py | |
parent | 01fa907aa8e7c475a76b407f35c635b26c9f47f8 (diff) | |
download | cpython-19c1462e8dca3319c8290e2edcce482bd18cb018.zip cpython-19c1462e8dca3319c8290e2edcce482bd18cb018.tar.gz cpython-19c1462e8dca3319c8290e2edcce482bd18cb018.tar.bz2 |
gh-99377: Add audit events for thread creation and clear (GH-99378)
Diffstat (limited to 'Lib/test/audit-tests.py')
-rw-r--r-- | Lib/test/audit-tests.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/Lib/test/audit-tests.py b/Lib/test/audit-tests.py index a411072..bf56cea 100644 --- a/Lib/test/audit-tests.py +++ b/Lib/test/audit-tests.py @@ -419,6 +419,48 @@ def test_sys_getframe(): sys._getframe() +def test_threading(): + import _thread + + def hook(event, args): + if event.startswith(("_thread.", "cpython.PyThreadState", "test.")): + print(event, args) + + sys.addaudithook(hook) + + lock = _thread.allocate_lock() + lock.acquire() + + class test_func: + def __repr__(self): return "<test_func>" + def __call__(self): + sys.audit("test.test_func") + lock.release() + + i = _thread.start_new_thread(test_func(), ()) + lock.acquire() + + +def test_threading_abort(): + # Ensures that aborting PyThreadState_New raises the correct exception + import _thread + + class ThreadNewAbortError(Exception): + pass + + def hook(event, args): + if event == "cpython.PyThreadState_New": + raise ThreadNewAbortError() + + sys.addaudithook(hook) + + try: + _thread.start_new_thread(lambda: None, ()) + except ThreadNewAbortError: + # Other exceptions are raised and the test will fail + pass + + def test_wmi_exec_query(): import _wmi |