Skip to content

Conversation

@picnixz
Copy link
Member

@picnixzpicnixz commented Sep 1, 2025

On main the following leaks:

$ ./python -X showrefcount -c 'import _random; s = _random.Random(); t = type(s); t._random = s'[42 refs, 26 blocks]

ZeroIntensity
ZeroIntensity previously approved these changes Sep 1, 2025
Copy link
Member

@ZeroIntensityZeroIntensity left a comment

Choose a reason for hiding this comment

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

LGTM with one idea.

@serhiy-storchaka
Copy link
Member

Wait, why is _random.Random mutable?

@ZeroIntensity
Copy link
Member

Probably because it would break code to change that.

@serhiy-storchaka
Copy link
Member

It became mutable in 3.9. I think this is a bug.

@picnixz
Copy link
MemberAuthor

It became mutable in 3.9. I think this is a bug.

I was also surprised but I just didn't want to break stuff here.

@kumaraditya303
Copy link
Contributor

It became mutable in 3.9. I think this is a bug.

Yes, I think adding IMMUTABLE flag was missed while conversion, it shouldn't be a mutable type.

@kumaraditya303
Copy link
Contributor

See #88074 where most of the converted types where made immutable, same should be done for random and epoll

@picnixzpicnixz marked this pull request as draft September 1, 2025 18:57
@picnixzpicnixz changed the title gh-116946: fully implement GC protocol for random.Randomgh-116946: add Py_TPFLAGS_IMMUTABLETYPE to _random.RandomSep 2, 2025
@picnixz
Copy link
MemberAuthor

@rhettinger Does this change satisfy you? do you want this to be backported?

Copy link
Member

@vstinnervstinner left a comment

Choose a reason for hiding this comment

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

LGTM

@vstinner
Copy link
Member

do you want this to be backported?

Please don't backport this change. It would be surprising that a class becomes immutable in 3.x.y bugfix release.

Copy link
Member

@serhiy-storchakaserhiy-storchaka left a comment

Choose a reason for hiding this comment

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

LGTM, but I would prefer a single large PR that fixes the 3.9 error by making all converted types immutable.

@picnixzpicnixz merged commit 51244ba into python:mainSep 3, 2025
54 of 63 checks passed
@picnixzpicnixz deleted the fix/gc/random-heap-types-116946 branch September 3, 2025 07:55
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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@picnixz@serhiy-storchaka@ZeroIntensity@kumaraditya303@vstinner@rhettinger