|
45 | 45 | Py_GIL_DISABLED, |
46 | 46 | no_rerun, |
47 | 47 | force_not_colorized_test_class, |
48 | | - catch_unraisable_exception |
| 48 | + catch_unraisable_exception, |
| 49 | + infinite_recursion, |
| 50 | + run_with_limited_c_stack, |
| 51 | + skip_emscripten_stack_overflow, |
| 52 | + skip_wasi_stack_overflow |
49 | 53 | ) |
50 | 54 | from test.support.import_helper import ( |
51 | 55 | forget, make_legacy_pyc, unlink, unload, ready_to_import, |
@@ -782,6 +786,24 @@ def run(): |
782 | 786 | finally: |
783 | 787 | del sys.path[0] |
784 | 788 |
|
| 789 | + @cpython_only |
| 790 | + @skip_emscripten_stack_overflow() |
| 791 | + @skip_wasi_stack_overflow() |
| 792 | + @run_with_limited_c_stack(depth=100_000) |
| 793 | + def test_acquire_lock_near_c_stack_limit(self): |
| 794 | + # _imp.acquire_lock() must refuse to take the import lock when there |
| 795 | + # is not enough C stack left to release it again. |
| 796 | + def recurse(_): |
| 797 | + _imp.acquire_lock() |
| 798 | + _imp.release_lock() |
| 799 | + list(map(recurse, [None])) |
| 800 | + |
| 801 | + with infinite_recursion(100_000): |
| 802 | + with self.assertRaisesRegex(RecursionError, |
| 803 | + 'acquiring the import lock'): |
| 804 | + recurse(None) |
| 805 | + self.assertFalse(_imp.lock_held()) |
| 806 | + |
785 | 807 | @unittest.skipUnless(sys.platform == "win32", "Windows-specific") |
786 | 808 | def test_dll_dependency_import(self): |
787 | 809 | from _winapi import GetModuleFileName |
|
0 commit comments