Skip to content

gh-116946: add Py_TPFLAGS_IMMUTABLETYPE to select.[e]poll - #138340

Merged
kumaraditya303 merged 5 commits into
python:mainfrom
picnixz:fix/gc/select-heap-types-116946
Sep 2, 2025
Merged

gh-116946: add Py_TPFLAGS_IMMUTABLETYPE to select.[e]poll#138340
kumaraditya303 merged 5 commits into
python:mainfrom
picnixz:fix/gc/select-heap-types-116946

Conversation

@picnixz

@picnixzpicnixz commented Sep 1, 2025

Copy link
Copy Markdown
Member

I'm not sure about kqueue as I can't check this myself. However note the following leak on main:

$ ./python -X showrefcount -c 'import select; s = select.poll(); t = type(s); t._do = s'[74 refs, 43 blocks]

Instead of implementing the full GC protocol, we can make the types immutable.

Rationale for not backporting this: #138341 (comment).

Comment threadModules/selectmodule.c
Comment threadModules/selectmodule.c Outdated
@picnixz
picnixz marked this pull request as draft September 1, 2025 18:56
@picnixzpicnixz changed the title gh-116946: fully implement GC protocol for select.[e]pollgh-116946: correctly support GC for select.[e]pollSep 2, 2025
@picnixz
picnixzforce-pushed the fix/gc/select-heap-types-116946 branch from 50a32c4 to 55c88e4CompareSeptember 2, 2025 08:32
@picnixz
picnixzforce-pushed the fix/gc/select-heap-types-116946 branch from 55c88e4 to 775f809CompareSeptember 2, 2025 08:33
@picnixz
picnixz marked this pull request as ready for review September 2, 2025 08:35
@picnixzpicnixz changed the title gh-116946: correctly support GC for select.[e]pollgh-116946: add Py_TPFLAGS_IMMUTABLETYPE to select.[e]pollSep 2, 2025
Comment threadModules/selectmodule.c

@vstinnervstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

I don't know if "cannot create cycles as it only contains exact ints" comment is correct or not.

Comment threadMisc/NEWS.d/next/Library/2025-09-02-10-27-21.gh-issue-116946.VxXNGD.rst Outdated
@picnixz

Copy link
Copy Markdown
MemberAuthor

I don't know if "cannot create cycles as it only contains exact ints" comment is correct or not.

That's why I actually asked. The ints are constructed internally (AFAIU) so I that's why I didn't visit the dictionary. But I can visit it just to be sure.

…xXNGD.rst
Co-authored-by: Victor Stinner <vstinner@python.org>
@kumaraditya303
kumaraditya303 enabled auto-merge (squash) September 2, 2025 17:28
@kumaraditya303
kumaraditya303 merged commit 3ff00c7 into python:mainSep 2, 2025
45 checks passed
@picnixz
picnixz deleted the fix/gc/select-heap-types-116946 branch September 2, 2025 18:11
lkollar pushed a commit to lkollar/cpython that referenced this pull request Sep 9, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@picnixz@vstinner@kumaraditya303