You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Creation of an internal decimal context for _pylong has side effects on decimal #123284
The _decimal module was recently fixed in #123243. I also found that _pylong leaks globals due to the creation of a global context to use as a local context:
This context is used as with decimal.localcontext(_unbounded_dec_context). On the other hand decimal.getcontext().copy() returns a copy of the decimal context for the current thread (or set it to decimal.DefaultContext if none exists). Instead of setting it like that, I suggest that we construct a decimal.Context() object directly in _pylong instead of possibly polluting the decimal module (whether it's the C or the python implementation).
changed the title [-]Creation of an internal decimal context for `_pylong` has side effects on `decimal` (and refleaks)[/-][+]Creation of an internal decimal context for `_pylong` has side effects on `decimal`[/+]on Aug 24, 2024
I just used ./python -X showrefcounts -c 'import _pylong'. I don't really know if it's the _pylong module itself that leaks or if it's the decimal module that leaks because decimal.getcontext() was called.
What I however know is that there is a side-effect on decimal because _pylong calls decimal.getcontext() and thus sets the decimal default's context. I'm not really sure whether it's an issue or not, but I was just looking at all ./python -X showrefcounts -c 'import MODULE' for every module in Lib to see whether a module leaked or not. Feel free to close if you think this is a non-issue though.
Activity
[-]Creation of an internal decimal context for `_pylong` has side effects on `decimal` (and refleaks)[/-][+]Creation of an internal decimal context for `_pylong` has side effects on `decimal`[/+]vstinner commentedon Sep 5, 2024
How do you see such leak?
picnixz commentedon Sep 5, 2024
I just used
./python -X showrefcounts -c 'import _pylong'. I don't really know if it's the_pylongmodule itself that leaks or if it's thedecimalmodule that leaks becausedecimal.getcontext()was called.What I however know is that there is a side-effect on
decimalbecause_pylongcallsdecimal.getcontext()and thus sets the decimal default's context. I'm not really sure whether it's an issue or not, but I was just looking at all./python -X showrefcounts -c 'import MODULE'for every module inLibto see whether a module leaked or not. Feel free to close if you think this is a non-issue though.vstinner commentedon Sep 5, 2024
The problem is unrelated to
_pylong, but related to decimal:picnixz commentedon Sep 5, 2024
Ok, one interrogation confirmed. I'll try to see what I can do tomorrow (not sure if I'll be able to though).
picnixz commentedon Sep 6, 2024
So the reference leaks will be fixed by another PR. I won't bother about setting the decimal's default thread context