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