| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
This PR needs a NEWS entry. Can a triager please add the interpreter-core label. |
Sorry, something went wrong.
Labels such as these are usually added on the issues rather than the PR. |
Sorry, something went wrong.
|
There seem to be similar races on all other settable attributes on function objects, so it probably makes sense to fix them all at once. |
Sorry, something went wrong.
Agree. I'll try to fix them. |
Sorry, something went wrong.
There was a problem hiding this comment.
I suspect some of these fields (e.g. func_code) are also accessed by the eval loop or other functions without the Python-level getter, and therefore without the lock. Can we look into finding those cases?
Sorry, something went wrong.
|
I think it's fine to just fix getters and setters of function in this PR. Fixing it for interp will require more massive changes which can be done separately if needed. |
Sorry, something went wrong.
| static PyGetSetDef func_getsetlist[] = { | ||
| FUNCTION___CODE___GETSETDEF | ||
| {"__defaults__", func_get_defaults, func_set_defaults}, | ||
| {"__kwdefaults__", func_get_kwdefaults, func_set_kwdefaults}, |
There was a problem hiding this comment.
Please add critical sections to all other ones as well
Sorry, something went wrong.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request. |
Sorry, something went wrong.
There was a problem hiding this comment.
Please reduce the diff, the getters and setters doesn't need to be moved, you should add @critical_section where it was already defined.
Sorry, something went wrong.
|
There are public C APIs like PyFunction_GetCode and PyFunction_GetGlobals which access only one field in function object. Should we use atomic load in these APIs? |
Sorry, something went wrong.
|
I have made the requested changes; please review again. |
Sorry, something went wrong.
|
Thanks for making the requested changes! @kumaraditya303: please review the changes made to this pull request. |
Sorry, something went wrong.
They should use also critical sections, not atomics. |
Sorry, something went wrong.
There was a problem hiding this comment.
Thanks again for taking this on @xuantengh.
We do not want to add locking for most of the PyFunctionObject attributes. In particular, we do not want locking for anything that will be accessed during function calls, like func_code, func_builtins, func_defaults, etc. both because it will affect single-threaded performance and because it will inhibit efficient multithreaded scaling.
Locking is probably fine for func_annotations, func_annotate, and func_typeparams. We should limit this PR to those fields.
We have a few general strategies for thread-safe accesses:
We will probably want to use either (3) or (4) for fields like func_code, but I want to be careful about making those changes and don't think we should pursue those as part of this PR.
Sorry, something went wrong.
I've reverted the PR to change only __annotate__, __annotations__ and __type_params. And now the PR only changes attributes which are not performance critical. |
Sorry, something went wrong.
There was a problem hiding this comment.
lgtm
Sorry, something went wrong.
|
Thanks @xuantengh for the PR, and @kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13. |
Sorry, something went wrong.
|
Sorry, @xuantengh and @kumaraditya303, I could not cleanly backport this to 3.13 due to a conflict. cherry_picker 55f17b77c305be877ac856d6426b13591cbc7fc8 3.13 |
Sorry, something went wrong.
…tations__` and `__type_params__` in free-threading build (python#129016) (cherry picked from commit 55f17b7)
|
GH-129729 is a backport of this pull request to the 3.13 branch. |
Sorry, something went wrong.
…tations__` and `__type_params__` in free-threading build (python#129016)
…tations__` and `__type_params__` in free-threading build (python#129016)
…otations__` and `__type_params__` in free-threading build (GH-129016) (#129729) * gh-128714: Fix function object races in `__annotate__`, `__annotations__` and `__type_params__` in free-threading build (#129016) (cherry picked from commit 55f17b7) --------- Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
| Back | FazBrowse Home | New Git URL |
This PR aims to fix the potential data races when getting and setting funcobject __annotations__. And it also add the test to validate the consistency under concurrent reads and writes.