Skip to content

Thread limit introspection API, part 1: API scope#213

Open
itamarst wants to merge 27 commits into
joblib:masterfrom
itamarst:211-thread-limit-introspection-api
Open

Thread limit introspection API, part 1: API scope#213
itamarst wants to merge 27 commits into
joblib:masterfrom
itamarst:211-thread-limit-introspection-api

Conversation

@itamarst

Copy link
Copy Markdown
Contributor

Fixes #211.

Add info to determine the scope of the thread-limit-setting API (thread local, process-wide, unknown). Introspecting the semantics of the thread pool are going to be a separate PR, assuming that can be done reasonably.

@ogrisel ogrisel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it a bit disturbing that calling threadpoolctl.threadpool_info can temporarily mutate the libraries global state in a non-thread safe way.

The alternative would be to hardcode expected scopes in LibController for all known libraries (and return "unknown" otherwise) and only call _determine_api_scope in tests or by passing a non-default kwarg value: threadpool_ctl.threadpool_info(api_scopes="effective") (and api_scopes="expected" would be the default) for instance.

Comment thread tests/test_threadpoolctl.py Outdated
Comment thread threadpoolctl.py
Comment thread threadpoolctl.py Outdated
Comment thread threadpoolctl.py Outdated
@ogrisel

ogrisel commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Another interesting finding by looking at the CI results: BLIS is current_thread scoped contrary to other BLAS implementations.

@itamarst

Copy link
Copy Markdown
Contributor Author

I think it's useful to have it in python -m threadpoolctl for debugging and user bug reports, so maybe have the side-effect-y introspection gated behind a keyword argument to info()? Or it can just be some add-on processing that the command-line version does using lower-level functions.

@ogrisel

ogrisel commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

I am fine with introducing an extra CLI flag to enable the extra inspection work.

@itamarst

Copy link
Copy Markdown
Contributor Author

My feeling is:

  • As you said it shouldn't be on by default in the Python API because of risk of side-effects.
  • It should be on by default in the CLI because it won't actually run any user code, it's just for debugging, so may as well give all the available info.

@itamarst itamarst marked this pull request as ready for review June 30, 2026 20:25
Comment thread threadpoolctl.py Outdated
Comment thread threadpoolctl.py
Comment thread threadpoolctl.py Outdated
Comment thread threadpoolctl.py Outdated
Comment thread threadpoolctl.py Outdated
Comment thread threadpoolctl.py Outdated
Comment thread threadpoolctl.py
@itamarst itamarst force-pushed the 211-thread-limit-introspection-api branch from 2e6e276 to 95d77a0 Compare July 1, 2026 15:23
@itamarst

itamarst commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

++ /home/runner/miniconda3/bin/conda shell.posix reactivate
Traceback (most recent call last):
  File "/home/runner/miniconda3/bin/conda", line 12, in <module>
    from conda.cli import main
ModuleNotFoundError: No module named 'conda'

That's a fun error.

Probably due to conda/conda#16327

@itamarst

itamarst commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

I addressed or replied to all review comments. CI is broken for now, will try again later.

@itamarst

itamarst commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

I wonder why a filter of {'internal_api': 'openblas', 'threading_layer': 'pthreads'} is returning a BLISController... will get to that next week, I guess.

@itamarst

itamarst commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

I wonder why a filter of {'internal_api': 'openblas', 'threading_layer': 'pthreads'} is returning a BLISController... will get to that next week, I guess.

Ah, I misunderstood the logic, it's OR not AND. Will fix.

@itamarst itamarst requested a review from ogrisel July 6, 2026 17:49
@itamarst

itamarst commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

Ready for another round of review, I think.

@ogrisel ogrisel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a changelog entry for this. Otherwise, LGTM.

Any opinion @jeremiedbb?

Comment thread tests/test_api_introspection.py
@ogrisel

ogrisel commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

The CI failures seem to be unrelated I think. If so we can fix them in a dedicated PR.

@itamarst

itamarst commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

The CI failures seem to be unrelated I think. If so we can fix them in a dedicated PR.

I believe there's an outstanding PR that fixes one of them, yes.

@itamarst

itamarst commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

Added changelog and explanatory comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API to introspect the scope of what thread pool limit set/get API actually does

2 participants