-
Notifications
You must be signed in to change notification settings - Fork 37
Thread limit introspection API, part 1: API scope #213
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
Open
itamarst
wants to merge
27
commits into
joblib:master
Choose a base branch
from
itamarst:211-thread-limit-introspection-api
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+250
−14
Open
Changes from 8 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
28bd246
Sketch of determine_api_scope.
itamarst 128c4ef
Add API scope to info.
itamarst 8637248
Reformat
itamarst 6946867
Reformat.
itamarst 31bbcf5
Try to work with older Python.
itamarst f27e6f2
Better names.
itamarst 0d4dde5
Test for expected API scopes for different libraries.
itamarst 60dd11c
Be more lenient.
itamarst 2c985b6
Convert into test to check _determine_api_scope(), rather than of exp…
itamarst bb7b528
Don't include API scope in info by default, since it might have side-…
itamarst 7fee2dc
Minor cleanups.
itamarst 1c6ae79
Improve docs.
itamarst 9ad8382
Match command-line behavior
itamarst d306c55
Give up on live testing, it's too inconsistent.
itamarst 8740d13
Cleanups from code review
itamarst 12a9d96
Review comments: better names, don't raise exception.
itamarst 95d77a0
Try to reintroduce a test that checks real libraries.
itamarst 3c831ad
Better explanation.
itamarst db35024
There's another option
itamarst b076937
Document better the limitations of this parameter.
itamarst a686a9b
Correct filtering logic.
itamarst fa3be78
Black
itamarst 0e44183
New architecture that showed up from a CI run
itamarst 586809d
FlexiBLAS support.
itamarst 5899f47
Correct default
itamarst 8d6bee5
Add changelog entry
itamarst 3bc6b79
Explanatory comment.
itamarst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| """ | ||
| Tests for get/set number of threads API introspection. | ||
| """ | ||
|
|
||
| from threading import local as threadlocal | ||
|
|
||
| import pytest | ||
|
|
||
| from threadpoolctl import _APIScope, _determine_api_scope | ||
|
|
||
|
|
||
| class FakeThreadLocalAPI(threadlocal): | ||
| """Thread-local num threads setting API.""" | ||
|
|
||
| def get(self) -> int: | ||
| return getattr(self, "num_threads", 17) | ||
|
|
||
| def set(self, n: int) -> None: | ||
| self.num_threads = n | ||
|
|
||
|
|
||
| class FakeProcesswideAPI: | ||
| """Process-wide num threads setting API.""" | ||
|
|
||
| def __init__(self, num_threads: int): | ||
| self.num_threads = num_threads | ||
|
|
||
| def get(self) -> int: | ||
| return self.num_threads | ||
|
|
||
| def set(self, n: int) -> None: | ||
| self.num_threads = n | ||
|
|
||
|
|
||
| def test_determine_api_scope_thread_local(): | ||
| """ | ||
| Check ``_determine_api_scope()`` can correctly diagnose a trivial | ||
| thread-local implementation. | ||
| """ | ||
| api = FakeThreadLocalAPI() | ||
| assert _determine_api_scope(api.get, api.set) == _APIScope.CURRENT_THREAD | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("default", [1, 17]) | ||
| def test_determine_api_scope_processiwde(default: int): | ||
| """ | ||
| Check ``determine_api_scope()`` can correctly diagnose a trivial | ||
| process-wide implementation. | ||
| """ | ||
| api = FakeProcesswideAPI(default) | ||
| assert _determine_api_scope(api.get, api.set) == _APIScope.PROCESS |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.