Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9480837
Don't restore the limits if setting them was a no-op.
itamarst Nov 5, 2026
968373b
Changelog entry
itamarst Nov 5, 2026
80a69c0
Ensure other LibControllers are restored correctly
itamarst Nov 5, 2026
b5c7139
Better explanation
itamarst Nov 5, 2026
b19b653
Lint
itamarst Nov 5, 2026
a915356
Deal with platform edge cases
itamarst Nov 5, 2026
aa787f6
Mark correctly
itamarst Nov 5, 2026
bdfa41f
Correct usage
itamarst Nov 5, 2026
359a595
Test another usage pattern.
itamarst Nov 5, 2026
9d236aa
Better name and docs
itamarst Nov 5, 2026
919e2b4
correct platform name
itamarst Nov 5, 2026
c309842
Reformat
itamarst Nov 5, 2026
f204aaa
Fix the _other_ wrong string
itamarst Nov 5, 2026
36b898d
Test for another race condition
itamarst Nov 6, 2026
2e188ac
Fix for the race condition
itamarst Nov 6, 2026
2a39126
Explain a bit better
itamarst Nov 9, 2026
b9a13b0
Better description
itamarst Nov 9, 2026
0de10cc
Make additional info from OpenBLASController even more private
itamarst Nov 10, 2026
2d5d66d
Reformat
itamarst Nov 10, 2026
0bbcfce
Tweak
itamarst Nov 10, 2026
e6c0c34
Stick to ubuntu-24.04 for now (ubuntu-latest is now 26.04)
itamarst Nov 10, 2026
11eaef5
Work for subclasses as well
itamarst Nov 12, 2026
f73c3cd
Switch to back to just that class
itamarst Nov 12, 2026
24c950c
More constrained test
itamarst Nov 12, 2026
a7908cd
Add new API for Python thread pool workers
itamarst Nov 16, 2026
8d9790a
Skip on FlexiBLAS for now
itamarst Nov 16, 2026
e6d05df
Make testing more thorough
itamarst Nov 17, 2026
6c3d36c
Fix race condition for multiple OpenBLAS too.
itamarst Nov 17, 2026
a092fe8
Experiment: Always use FlexiBLAS last
itamarst Nov 17, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ jobs:

# Linux environment with development versions of numpy and scipy
- name: pylatest_pip_dev
os : ubuntu-latest
os : ubuntu-24.04
PACKAGER: "pip-dev"
PYTHON_VERSION: "*"
CC_OUTER_LOOP: "gcc"
Expand All @@ -134,7 +134,7 @@ jobs:

# Linux + Python 3.10 and homogeneous runtime nesting.
- name: py310_conda_openblas_clang_clang
os: ubuntu-latest
os: ubuntu-24.04
PACKAGER: "conda"
PYTHON_VERSION: "3.10"
BLAS: "openblas"
Expand All @@ -145,7 +145,7 @@ jobs:
# Linux environment with MKL and Clang (known to be unsafe for
# threadpoolctl) to only test the warning from multiple OpenMP.
- name: pylatest_conda_mkl_clang_gcc
os: ubuntu-latest
os: ubuntu-24.04
PYTHON_VERSION: "*"
PACKAGER: "conda"
BLAS: "mkl"
Expand All @@ -154,7 +154,7 @@ jobs:
TESTS: "libomp_libiomp_warning"
# Linux environment with MKL, safe for threadpoolctl.
- name: pylatest_conda_mkl_gcc_gcc
os: ubuntu-latest
os: ubuntu-24.04
PYTHON_VERSION: "*"
PACKAGER: "conda"
BLAS: "mkl"
Expand All @@ -166,15 +166,15 @@ jobs:
# Linux + Python 3.11 with numpy / scipy installed with pip from PyPI
# and heterogeneous OpenMP runtimes.
- name: py311_pip_openblas_gcc_clang
os: ubuntu-latest
os: ubuntu-24.04
PACKAGER: "pip"
PYTHON_VERSION: "3.11"
CC_OUTER_LOOP: "gcc"
CC_INNER_LOOP: "clang-18"
# Linux + conda-forge Python RC, extra deps from PyPI.
# OpenCV is omitted: no wheels for the current RC ABI yet.
- name: pyrc_pip
os: ubuntu-latest
os: ubuntu-24.04
PACKAGER: "pip"
# Using the "*" marker does not select the latest RC release
# from the conda-forge `python_rc` channel hence the need to pin
Expand All @@ -185,7 +185,7 @@ jobs:
CC_INNER_LOOP: "gcc"
# Linux + conda-forge free-threaded Python RC, extra deps from PyPI.
- name: pyrc_ft_pip
os: ubuntu-latest
os: ubuntu-24.04
PACKAGER: "pip"
# Using the "*" marker does not select the latest RC release
# from the conda-forge `python_rc` channel hence the need to pin
Expand All @@ -197,7 +197,7 @@ jobs:
CC_INNER_LOOP: "gcc"
# Linux environment with numpy from conda-forge channel and openblas-openmp
- name: pylatest_conda_forge
os: ubuntu-latest
os: ubuntu-24.04
PACKAGER: "conda-forge"
PYTHON_VERSION: "*"
BLAS: "openblas"
Expand All @@ -207,7 +207,7 @@ jobs:
CC_INNER_LOOP: "gcc"
# Linux environment with no numpy and heterogeneous OpenMP runtimes.
- name: pylatest_conda_nonumpy_gcc_clang
os: ubuntu-latest
os: ubuntu-24.04
PACKAGER: "conda"
PYTHON_VERSION: "*"
NO_NUMPY: "true"
Expand All @@ -216,7 +216,7 @@ jobs:

# Linux environments with numpy linked to BLIS
- name: pylatest_blis_gcc_clang_openmp
os: ubuntu-latest
os: ubuntu-24.04
PYTHON_VERSION: "*"
INSTALL_BLAS: "blis"
BLIS_NUM_THREAEDS: "4"
Expand All @@ -225,7 +225,7 @@ jobs:
BLIS_CC: "clang-18"
BLIS_ENABLE_THREADING: "openmp"
- name: pylatest_blis_clang_gcc_pthreads
os: ubuntu-latest
os: ubuntu-24.04
PYTHON_VERSION: "*"
INSTALL_BLAS: "blis"
BLIS_NUM_THREADS: "4"
Expand All @@ -234,7 +234,7 @@ jobs:
BLIS_CC: "gcc-12"
BLIS_ENABLE_THREADING: "pthreads"
- name: pylatest_blis_no_threading
os: ubuntu-latest
os: ubuntu-24.04
PYTHON_VERSION: "*"
INSTALL_BLAS: "blis"
BLIS_NUM_THREADS: "1"
Expand All @@ -245,7 +245,7 @@ jobs:

# Linux env with FlexiBLAS
- name: pylatest_flexiblas
os: ubuntu-latest
os: ubuntu-24.04
PYTHON_VERSION: "*"
INSTALL_BLAS: "flexiblas"
PLATFORM_SPECIFIC_PACKAGES: "mkl"
Expand All @@ -254,7 +254,7 @@ jobs:

# Python 3.14, free-threaded
- name: py314_freethreaded_pip_openblas
os: ubuntu-latest
os: ubuntu-24.04
PACKAGER: "conda-forge"
BLAS: "openblas"
PYTHON_VERSION: "3.14"
Expand Down
7 changes: 6 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
3.9.0 (under development)
3.8.1 (under development)
=========================

- Fix a number of race conditions in OpenBLAS-pthreads/win32 controlling thread
logic, that could result in unexpected number of threads being set.
https://github.com/joblib/threadpoolctl/pull/300


3.8.0 (2026-11-05)
==================

Expand Down
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,12 @@ with (
# APIs operate on a process-wide basis. Because it's a context manager, it
# will restore the limits after the ``with`` is done.
controller.limit(limits=1),
# Make sure each Python worker thread also calls threadpool_limits(). If
# you're using another thread pool class, you will need to do so some other
# way.
ThreadPoolExecutor(4, initializer=lambda: controller.limit(limits=1)) as pool,
# Make sure each Python worker thread also sets limits, using an API that
# is specifically for Python worker threads. If you're using another thread
# pool class, you will need to do so some other way.
ThreadPoolExecutor(
4, initializer=lambda: controller.limit_in_worker_thread(limits=1)
) as pool,
):
# ... run some BLAS-using code in the thread pool ...
pool.map(somefunc, someargs)
Expand All @@ -309,7 +311,9 @@ with (
controller = ThreadpoolController()
with (
controller.limit(limits=2),
ThreadPoolExecutor(4, initializer=lambda: controller.limit(limits=2)) as pool,
ThreadPoolExecutor(
4, initializer=lambda: controller.limit_in_worker_thread(limits=2)
) as pool,
):
# ... run some BLAS-using code in the thread pool ...
pool.map(somefunc, someargs)
Expand All @@ -323,7 +327,9 @@ from threadpoolctl import ThreadpoolController
controller = ThreadpoolController()
try:
limiter = controller.limit(limits=1)
with ThreadPoolExecutor(4, initializer=lambda: controller.limit(limits=1)) as pool:
with ThreadPoolExecutor(
4, initializer=lambda: controller.limit_in_worker_thread(limits=1)
) as pool:
# ... run some BLAS-using code in the thread pool ...
pool.map(somefunc, someargs)
finally:
Expand All @@ -350,7 +356,7 @@ with CONTROLLER.limit(limits=1):

def limit_then_do_work(*args, **kwargs):
# Set a limit on OpenMP in the current thread:
CONTROLLER.limit(limits=1)
CONTROLLER.limit_in_worker_thread(limits=1)
# Do the actual work:
return do_real_work_with_openmp(*args, **kwargs)

Expand All @@ -366,7 +372,7 @@ with CONTROLLER.limit(limits=4):
with CONTROLLER.limit(limits=2):

def limit_then_do_work2(*args, **kwargs):
CONTROLLER.limit(limits=2)
CONTROLLER.limit_in_worker_thread(limits=2)
return do_even_more_real_work_with_openmp(*args, **kwargs)

results3 = POOL.map(limit_then_do_work2, results2)
Expand Down
Loading
Loading