GeezerVison is showing github.com — gh-100227: Port dup3_works to the module state variable. by corona10 · Pull Request #100262 · python/cpython
Conversation
corona10
commented
Dec 15, 2022
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
dup3_works is safe to be ported as the module state variable since there is just one writing accessing in L9462.
Even if there are duplicated updatings for the dup3_works due to the race condition, dup3_works will not be updated anymore after the initial trial.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
netlify
Bot
commented
Dec 15, 2022
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
✅ Deploy Preview for python-cpython-preview canceled.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
IMHO, we should keep all cached process-level resource availability/capability checks as static global variables. I'm specifically talking about the following group (and any others we might add in the future):
|
## indicators for resource availability/capability |
|
# (set during first init) |
|
Python/bootstrap_hash.c py_getrandom getrandom_works - |
|
Python/fileutils.c - _Py_open_cloexec_works - |
|
Python/fileutils.c set_inheritable ioctl_works - |
|
# (set lazily, *after* first init) |
|
# XXX Is this thread-safe? |
|
Modules/posixmodule.c os_dup2_impl dup3_works - |
Making any of them per-interpreter is unnecessary since the value will always be uniform for the process. Moving them to _PyRuntimeState did not seem correct because the value is independent of Python's runtime and should not change across init/fini cycles.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
tl;dr I'd rather we keep dup3_works as a static variable and not move it to the module state.
In the case of dup3_works the only concern I had was if there were any potential races, since the value is set lazily after runtime init. Looking at it again, there really isn't a race there. The only real race would be if two threads both see a -1 value (line 9463, if (dup3_works == -1)) and set the variable. However, that has no consequences if we assume word-size values like this are written atomically, which they should be. So let's not worry about it.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
In the case of dup3_works the only concern I had was if there were any potential races, since the value is set lazily after runtime init. Looking at it again, there really isn't a race there
Okay, I understood :)
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Thanks for working on this though!
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
ericsnowcurrently
Awaiting requested review from ericsnowcurrently
ericsnowcurrently is a code owner
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|