`threadpool_limits` is not thread-safe under `ThreadPoolExecutor`
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 48/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 領域
- backend, performance
調査の方向性
Start by reading the threadpool_limits context manager and its tests; the issue does not name their file paths. Reproduce the reported behavior with the supplied ThreadPoolExecutor example and inspect how limits are changed and restored across overlapping contexts. Done means concurrent workers consistently observe the intended limit and the original limits are restored afterward.
索引モデルが issue の本文から書いたものです。
説明
When using threadpoolctl.threadpool_limits inside multiple Python threads (e.g. via ThreadPoolExecutor), the thread limit is not reliably enforced.
Despite using with threadpool_limits(limits=2) inside each worker, some threads observe OpenBLAS using the full default thread count.
Reproducible Example
#!/usr/bin/env python3
from threadpoolctl import threadpool_limits, threadpool_info
import torch
from concurrent.futures import ThreadPoolExecutor, as_completed
def worker(i):
# NOTE: this appears to be process-global, not thread-local
with threadpool_limits(limits=2):
a = torch.randn(512, 256, device="cpu")
b = torch.randn(256, 512, device="cpu")
_ = a @ b
info = threadpool_info()
print(f"[worker {i}] threadpool_info:", info)
return info
results = []
with ThreadPoolExecutor(max_workers=8) as executor:
futures = [executor.submit(worker, i) for i in range(8)]
for fut in as_completed(futures):
results.append(fut.result())
print("final threadpool_info:")
print(threadpool_info())
Actual Output
[worker 6] threadpool_info: [{'user_api': 'blas', 'internal_api': 'openblas', 'num_threads': 2, 'prefix': 'libscipy_openblas', 'filepath': '/root/miniconda3/envs/gp_py311/lib/python3.11/site-packages/numpy.libs/libscipy_openblas64_-56d6093b.so', 'version': '0.3.29', 'threading_layer': 'pthreads', 'architecture': 'Haswell'}, {'user_api': 'openmp', 'internal_api': 'openmp', 'num_threads': 2, 'prefix': 'libgomp', 'filepath': '/root/miniconda3/envs/gp_py311/lib/python3.11/site-packages/torch/lib/libgomp.so.1', 'version': None}]
[worker 1] threadpool_info: [{'user_api': 'blas', 'internal_api': 'openblas', 'num_threads': 2, 'prefix': 'libscipy_openblas', 'filepath': '/root/miniconda3/envs/gp_py311/lib/python3.11/site-packages/numpy.libs/libscipy_openblas64_-56d6093b.so', 'version': '0.3.29', 'threading_layer': 'pthreads', 'architecture': 'Haswell'}, {'user_api': 'openmp', 'internal_api': 'openmp', 'num_threads': 2, 'prefix': 'libgomp', 'filepath': '/root/miniconda3/envs/gp_py311/lib/python3.11/site-packages/torch/lib/libgomp.so.1', 'version': None}]
[worker 5] threadpool_info: [{'user_api': 'blas', 'internal_api': 'openblas', 'num_threads': 24, 'prefix': 'libscipy_openblas', 'filepath': '/root/miniconda3/envs/gp_py311/lib/python3.11/site-packages/numpy.libs/libscipy_openblas64_-56d6093b.so', 'version': '0.3.29', 'threading_layer': 'pthreads', 'architecture': 'Haswell'}, {'user_api': 'openmp', 'internal_api': 'openmp', 'num_threads': 2, 'prefix': 'libgomp', 'filepath': '/root/miniconda3/envs/gp_py311/lib/python3.11/site-packages/torch/lib/libgomp.so.1', 'version': None}]
[worker 3] threadpool_info: [{'user_api': 'blas', 'internal_api': 'openblas', 'num_threads': 2, 'prefix': 'libscipy_openblas', 'filepath': '/root/miniconda3/envs/gp_py311/lib/python3.11/site-packages/numpy.libs/libscipy_openblas64_-56d6093b.so', 'version': '0.3.29', 'threading_layer': 'pthreads', 'architecture': 'Haswell'}, {'user_api': 'openmp', 'internal_api': 'openmp', 'num_threads': 2, 'prefix': 'libgomp', 'filepath': '/root/miniconda3/envs/gp_py311/lib/python3.11/site-packages/torch/lib/libgomp.so.1', 'version': None}]
[worker 4] threadpool_info: [{'user_api': 'blas', 'internal_api': 'openblas', 'num_threads': 2, 'prefix': 'libscipy_openblas', 'filepath': '/root/miniconda3/envs/gp_py311/lib/python3.11/site-packages/numpy.libs/libscipy_openblas64_-56d6093b.so', 'version': '0.3.29', 'threading_layer': 'pthreads', 'architecture': 'Haswell'}, {'user_api': 'openmp', 'internal_api': 'openmp', 'num_threads': 2, 'prefix': 'libgomp', 'filepath': '/root/miniconda3/envs/gp_py311/lib/python3.11/site-packages/torch/lib/libgomp.so.1', 'version': None}]
[worker 0] threadpool_info: [{'user_api': 'blas', 'internal_api': 'openblas', 'num_threads': 2, 'prefix': 'libscipy_openblas', 'filepath': '/root/miniconda3/envs/gp_py311/lib/python3.11/site-packages/numpy.libs/libscipy_openblas64_-56d6093b.so', 'version': '0.3.29', 'threading_layer': 'pthreads', 'architecture': 'Haswell'}, {'user_api': 'openmp', 'internal_api': 'openmp', 'num_threads': 2, 'prefix': 'libgomp', 'filepath': '/root/miniconda3/envs/gp_py311/lib/python3.11/site-packages/torch/lib/libgomp.so.1', 'version': None}]
[worker 7] threadpool_info: [{'user_api': 'blas', 'internal_api': 'openblas', 'num_threads': 2, 'prefix': 'libscipy_openblas', 'filepath': '/root/miniconda3/envs/gp_py311/lib/python3.11/site-packages/numpy.libs/libscipy_openblas64_-56d6093b.so', 'version': '0.3.29', 'threading_layer': 'pthreads', 'architecture': 'Haswell'}, {'user_api': 'openmp', 'internal_api': 'openmp', 'num_threads': 2, 'prefix': 'libgomp', 'filepath': '/root/miniconda3/envs/gp_py311/lib/python3.11/site-packages/torch/lib/libgomp.so.1', 'version': None}]
[worker 2] threadpool_info: [{'user_api': 'blas', 'internal_api': 'openblas', 'num_threads': 2, 'prefix': 'libscipy_openblas', 'filepath': '/root/miniconda3/envs/gp_py311/lib/python3.11/site-packages/numpy.libs/libscipy_openblas64_-56d6093b.so', 'version': '0.3.29', 'threading_layer': 'pthreads', 'architecture': 'Haswell'}, {'user_api': 'openmp', 'internal_api': 'openmp', 'num_threads': 2, 'prefix': 'libgomp', 'filepath': '/root/miniconda3/envs/gp_py311/lib/python3.11/site-packages/torch/lib/libgomp.so.1', 'version': None}]
final threadpool_info:
[{'user_api': 'blas', 'internal_api': 'openblas', 'num_threads': 2, 'prefix': 'libscipy_openblas', 'filepath': '/root/miniconda3/envs/gp_py311/lib/python3.11/site-packages/numpy.libs/libscipy_openblas64_-56d6093b.so', 'version': '0.3.29', 'threading_layer': 'pthreads', 'architecture': 'Haswell'}, {'user_api': 'openmp', 'internal_api': 'openmp', 'num_threads': 24, 'prefix': 'libgomp', 'filepath': '/root/miniconda3/envs/gp_py311/lib/python3.11/site-packages/torch/lib/libgomp.so.1', 'version': None}]
Some workers correctly observe num_threads = 2, while others observe num_threads = 24, even though all are wrapped in with threadpool_limits(limits=2).
Environment
Distributor ID: Ubuntu
Description: Ubuntu 22.04.5 LTS
Release: 22.04
Codename: jammy
torch: 2.9.0
numpy: 2.2.6
scipy: 1.16.2
threadpoolctl: 3.6.0
- 主要言語
- Python
- スター
- 434
- フォーク
- 38
- 平均マージ
- 2日 14時間
- マージ済み PR(30日)
- 8
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
joblib/threadpoolctl のほかの issue
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
joblib/threadpoolctl#274 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
joblib/threadpoolctl#271 ·
メンテナーはふだん 1 日以内に返信
-
Make it possible to inspect active/spin wait behavior of LLVM/Intel OpenMP via `kmp_get_blocktime`オープン
難易度 3/5 1〜2日 初心者へのやさしさ 42/100
joblib/threadpoolctl#270 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 22/100
joblib/threadpoolctl#261 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
Opt-in API that has a cached `ThreadpoolController`対応中かも @itamarst が 29 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
joblib/threadpoolctl#254 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
joblib/threadpoolctl の issue をすべて見る
似ている issue
-
follow-up
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
Download helper still uses huggingface_hub arguments removed in 1.0: USE_SYMLINKS is silently ignored and every download ends with a WinError 3 line対応中かも @li-lizhe が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
IPv6 node addresses produce an invalid request URL対応中かも @RaphaelFakhri が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
typesense/typesense-python#154 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
elastic/elasticsearch-py#3592 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
developmentseed/titiler-cmr#250 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信