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

kumaraditya303 merged 5 commits into
python:mainfrom
picnixz:fix/gc/select-heap-types-116946

Conversation

@picnixz

@picnixz picnixz 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 thread Modules/selectmodule.c Resolved
Comment thread Modules/selectmodule.c Resolved
@picnixz
picnixz marked this pull request as draft September 1, 2025 18:56
@picnixz picnixz changed the title gh-116946: fully implement GC protocol for select.[e]poll Sep 2, 2025
@picnixz
picnixz force-pushed the fix/gc/select-heap-types-116946 branch from 50a32c4 to 55c88e4 Compare September 2, 2025 08:32
@picnixz
picnixz force-pushed the fix/gc/select-heap-types-116946 branch from 55c88e4 to 775f809 Compare September 2, 2025 08:33
@picnixz
picnixz marked this pull request as ready for review September 2, 2025 08:35
@picnixz picnixz changed the title gh-116946: correctly support GC for select.[e]poll Sep 2, 2025
Comment thread Modules/selectmodule.c Resolved

@vstinner vstinner 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.

@picnixz

picnixz commented Sep 2, 2025

Copy link
Copy Markdown
Member Author

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:main Sep 2, 2025
@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 free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants