-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
GH-124742: Add the PYTHON_GC_THRESHOLD
environment variable.
#124743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
if (env == NULL || strcmp(env, "default") == 0) { | ||
return; | ||
} | ||
int threshold = -1; | ||
if (_Py_str_to_int(env, &threshold) < 0) { | ||
return; // parse failed, silently ignore | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, why ignore the error? If a user accidentally sets the variable to something that doesn't work, then they might end up very confused as to why Python is ignoring their request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm hoping this change can be included in the 3.13 RC and so I wanted it as simple and robust as possible. In the 'main' branch, I plan to re-work it so it becomes part of the config
structure and I would add an error raise there.
Maybe it is safe enough to raise an error here too. That would be consistent with the principle that "errors should not pass silently".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that making it return an error rather than nothing should still remain fairly simple, return
will just become return _PyStatus_ERR("...")
and whatnot.
I haven't paid too much attention to the incremental GC problem (#124567), but I'm assuming that this is a possible solution for it? That should help it go into the 3.13 release
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I don't think this would be enough for us to feel safe about including incremental GC into 3.13. In retrospect, the incremental GC should have been opt-in for 3.13 and would become default in 3.14 if people had good experience with it.
The point of this env var is to increase the chances that people will test their programs with a higher threshold with 3.13 and then when 3.14 release nears, we would have a better idea about how "aggressive" the default GC tuning should be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning an error _PyGC_Init
results in this kind of error:
Fatal Python error: _PyGC_Init: Invalid PYTHON_GC_THRESHOLD value.
Python runtime state: preinitialized
Current thread 0x00007fe0505d6740 (most recent call first):
<no Python frame>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that makes sense. We do the same for other env vars.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm hoping this change can be included in the 3.13 RC and so I wanted it as simple and robust as possible.
Since we have already reached the feature-freeze
stage and this is a new feature, it needs confirmation from @Yhg1s.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right. It's Thomas's call and I completely understand if he doesn't want it. There has already been a bit too much excitement with the RCs.
Closing. RC3 is out and I think GH-124772 is a better API to put into the |
Some comments of the approach taken here:
-X
option for it and to put it into theconfig
structure, so it can be set for embedding scenariosPYTHON_GC_STRATEGY
) as proposed on the Ideas forum. However, for 3.13 it seems safest to do the simplest possible thing and that's exposing thethreshold0
setting to be set by an env var.📚 Documentation preview 📚: https://cpython-previews--124743.org.readthedocs.build/