Threadpoolctl

3.6.0 · active · verified Sat Mar 28

Threadpoolctl is a Python library that provides helpers to limit the number of threads used in threadpool-backed native libraries, such as BLAS and OpenMP, commonly used in scientific computing and data science. The current version is 3.6.0, released on March 13, 2025. The library is actively maintained with regular updates to support new Python versions and improve functionality.

Warnings

Install

Imports

Quickstart

This script demonstrates how to introspect threadpool information and limit the number of threads used by BLAS libraries using threadpoolctl.

import numpy as np
from threadpoolctl import threadpool_info, threadpool_limits

# Introspect threadpool information
info = threadpool_info()
for lib in info:
    print(f"Library: {lib['internal_api']} ({lib['user_api']})")
    print(f"  Version: {lib['version']}")
    print(f"  Threads: {lib['num_threads']}")
    print(f"  Path: {lib['filepath']}")

# Limit threads for BLAS
with threadpool_limits(limits=1, user_api='blas'):
    a = np.random.randn(1000, 1000)
    a_squared = a @ a

view raw JSON →