Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-157429: Make test_detach_materialized_dict_no_memory deterministic - #157444

Open
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:test-class-nomemory-helper
Open

gh-157429: Make test_detach_materialized_dict_no_memory deterministic#157444
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:test-class-nomemory-helper

Conversation

@serhiy-storchaka

Copy link
Copy Markdown
Member

Add _testcapi.call_with_nomemory(start, stop, func, /, *args) which arms the allocation failure as set_nomemory(), calls func(*args) and removes the memory hooks, without executing any bytecode in between. So the work pending at the eval breaker (GC, deferred frees and refcount merges on free-threading builds) cannot run inside the failure window and consume the failing allocation.

The test now drops the last reference from C with lst.clear passed to this helper, so the first allocation in the window is always the one in detach_dict_from_object(). It only accepts the unraisable exception reported while clearing the managed dict, and its failure message lists what was actually seen for each n. Since nothing but the deallocation can run while the hooks are armed, the test no longer needs a subprocess.

Keeping ex.unraisable alive across iterations leaked references once the test ran in-process (gh-157443), so only exc_type and err_msg are taken out of the with block.

…nistic

Add _testcapi.call_with_nomemory() which arms the allocation failure,
calls a function and removes the memory hooks without executing any
bytecode in between, so that pending work at the eval breaker (GC,
deferred frees on free-threading builds) cannot consume the failing
allocation.

The test now drops the last reference from C with this helper, accepts
only the unraisable exception reported while clearing the managed dict,
and no longer needs to run in a subprocess.

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant