Skip to content

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

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

Thread limit introspection API, part 1: API scope#213
itamarst wants to merge 14 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
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