Feature: Threadsafe RcParams #383
Draft
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 PR makes our configuration system thread-safe and adds support for thread-local storage. This is particularly important when running tests in parallel (e.g., with pytest-xdist), where each test thread needs to modify configuration parameters without affecting other threads.
I started playing around with a recent PR that would be merged in the future(matplotlib/pytest-mpl#242 (comment)). This PR would prep for making it threadsafe -- speeding up local development. GHA has 2 threads per worker so it could be beneficial there, and otherwise not hurt.
The Problem
Currently, when multiple threads try to access or modify configuration parameters at the same time, we can get race conditions and data corruption. Also, there's no way for a thread to make temporary changes that are automatically cleaned up when the thread exits.
Proposed fix
The PR implements a thread-safe version of
_RcParamsthat:threading.RLock) to prevent race conditionsAdded tests
test_rcparams_thread_safety