gh-116738: Make _csv module thread-safe#118344
Merged
kumaraditya303 merged 17 commits intopython:mainfrom Oct 11, 2024
Merged
Conversation
corona10
reviewed
Apr 27, 2024
corona10
reviewed
Apr 27, 2024
corona10
reviewed
Apr 28, 2024
corona10
reviewed
Apr 28, 2024
aisk
commented
May 17, 2024
corona10
approved these changes
Jun 19, 2024
Member
corona10
left a comment
There was a problem hiding this comment.
LGTM, Sorry for the late.
@colesbury Do you have any comments about this?
colesbury
reviewed
Jul 8, 2024
Contributor
colesbury
left a comment
There was a problem hiding this comment.
Sorry for the long delay in reviewing this. Two requests:
- Let's change
field_limitto aPy_ssize_t. That seems more appropriate here and avoids the need for adding new atomic bindings. I'd prefer to avoid adding additional atomic bindings because its more code to maintain and its easy to add subtle bugs in the atomic bindings. Additionally,field_limitis compared tofield_len, which is already aPy_ssize_t. - Let's use relaxed atomics for reading and writing
field_limit, e.g.,FT_ATOMIC_STORE_SSIZE_RELAXED. Relaxed ordering is fine for these sorts of global settings.
For the data type change:
%ld->%zdPyLong_AsLong->PyLong_AsSsize_t
Contributor
Author
Thanks for the review, updated! |
kumaraditya303
approved these changes
Oct 11, 2024
|
Thanks @aisk for the PR, and @kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13. |
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this pull request
Oct 11, 2024
(cherry picked from commit a00221e) Co-authored-by: AN Long <[email protected]>
|
GH-125328 is a backport of this pull request to the 3.13 branch. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This extension module has some module state values which may be read or written in different threads:
field_limit: A simple integer value to store the maximum field size for the parser;dialects: A dict value to store all the dialects by string names.field_limitThere is a public function
field_size_limitthat can read and write it,using a critical section to protect it. For other internal usages,_Py_atomic_load_longand_Py_atomic_store_longare used to make it thread safe.dialectsThere are three public functions
get_dialect,unregister_dialectandlist_dialectsthat can access this field.For the first two functions, a critical section is used to protect it.And the
list_dialectsfunction just returns the dict's keys withPyDict_Keys. I think its result is readonly andPyDict_Keysitself is thread safe, so we don't need to do anything.Other internal usages of
dialectsinvolve accessing its value withget_dialect_from_registry, which simply callsPyDict_GetItemRefand returns the result. I think we don't need to change it too.Update: I think these APIs is just call
dictAPIs which is already thread-safe, and there are no other state changes inside these APIs, and no intermediate variables need to protect in these functions, so we don't need add locks on them.