0
# Thread Pool Introspection
1
2
Discover and inspect thread pool libraries currently loaded in the Python process. This capability provides detailed information about each detected library including implementation details, version information, and current thread settings.
3
4
## Capabilities
5
6
### Basic Introspection
7
8
Get information about all thread pool libraries currently loaded in the process.
9
10
```python { .api }
11
def threadpool_info():
12
"""
13
Return thread pool information for all detected libraries.
14
15
Scans loaded shared libraries and returns info for supported thread pool
16
libraries (BLAS implementations and OpenMP runtimes).
17
18
Returns:
19
list[dict]: List of library information dictionaries, each containing:
20
- user_api (str): Standardized API ('blas' or 'openmp')
21
- internal_api (str): Implementation name ('openblas', 'mkl', 'blis', 'flexiblas', 'openmp')
22
- prefix (str): Shared library filename prefix
23
- filepath (str): Full path to the loaded shared library
24
- version (str | None): Library version if detectable
25
- num_threads (int): Current maximum thread count
26
- Additional implementation-specific attributes
27
"""
28
```
29
30
### Usage Examples
31
32
```python
33
from threadpoolctl import threadpool_info
34
import numpy # This loads BLAS libraries
35
36
# Get information about all thread pool libraries
37
info = threadpool_info()
38
39
for lib in info:
40
print(f"Library: {lib['internal_api']} ({lib['user_api']})")
41
print(f" Version: {lib['version']}")
42
print(f" Threads: {lib['num_threads']}")
43
print(f" Path: {lib['filepath']}")
44
45
# BLAS libraries may have additional attributes
46
if lib['user_api'] == 'blas':
47
if 'threading_layer' in lib:
48
print(f" Threading: {lib['threading_layer']}")
49
if 'architecture' in lib:
50
print(f" Architecture: {lib['architecture']}")
51
print()
52
```
53
54
### Library-Specific Information
55
56
Different library implementations provide additional attributes beyond the standard set:
57
58
#### OpenBLAS Libraries
59
- `threading_layer`: Threading backend ("openmp", "pthreads", "disabled")
60
- `architecture`: Target architecture detected by OpenBLAS
61
62
#### BLIS Libraries
63
- `threading_layer`: Threading backend ("openmp", "pthreads", "disabled")
64
- `architecture`: Target architecture detected by BLIS
65
66
#### MKL Libraries
67
- `threading_layer`: Threading layer ("intel", "sequential", "pgi", "gnu", "tbb", "not specified")
68
69
#### FlexiBLAS Libraries
70
- `available_backends`: List of configured backend names
71
- `loaded_backends`: List of currently loaded backend names
72
- `current_backend`: Name of the currently active backend
73
74
### Common Usage Patterns
75
76
```python
77
from threadpoolctl import threadpool_info
78
79
# Check if specific libraries are loaded
80
info = threadpool_info()
81
has_openblas = any(lib['internal_api'] == 'openblas' for lib in info)
82
has_openmp = any(lib['user_api'] == 'openmp' for lib in info)
83
84
# Find libraries with many threads
85
high_thread_libs = [lib for lib in info if lib['num_threads'] > 4]
86
87
# Group by API type
88
blas_libs = [lib for lib in info if lib['user_api'] == 'blas']
89
openmp_libs = [lib for lib in info if lib['user_api'] == 'openmp']
90
91
print(f"Found {len(blas_libs)} BLAS libraries")
92
print(f"Found {len(openmp_libs)} OpenMP libraries")
93
```