-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: system threads persist in threadpool_limits context manager #132
Comments
The goal of `threadpoolctl` is to dynamically limit the number of threads
used in a threadpool. The library does this by introspecting the linked
libraries and setting their limit. This means that `threadpoolctl` only
works on libraries that are already loaded. If you import `numpy` before
the context, `threadpoolctl` should work as expected.
Le dim. 15 janv. 2023 à 03:55, Cade Daniel ***@***.***> a
écrit :
… Hi, thanks for the work on this package! I would like to use it but I am
not getting the expected behavior.
When I import numpy inside a threadpool_limits context manager, I expect
the number of threads to be limited by threadpool_limits.
What happens is that the thread count is not changed.
Is this user error or a bug?
#!/usr/bin/env python3
from threadpoolctl import threadpool_limits, threadpool_infoimport psutilimport os
proc = psutil.Process(os.getpid())
print('pid', os.getpid())print('threads:', len(proc.threads()))print(threadpool_info())
with threadpool_limits(limits=2, user_api='blas'):
import numpy
print('numpy imported')
print('threads:', len(proc.threads()))
print(threadpool_info())
print('threads:', len(proc.threads()))print(threadpool_info())
pid 60392
threads: 1
[]
numpy imported
threads: 36
[{'user_api': 'blas', 'internal_api': 'openblas', 'prefix': 'libopenblas', 'filepath': '/home/ray/anaconda3/lib/python3.10/site-packages/numpy.libs/libopenblas64_p-r0-15028c96.3.21.so', 'version': '0.3.21', 'threading_layer': 'pthreads', 'architecture': 'SkylakeX', 'num_threads': 36}]
threads: 36
[{'user_api': 'blas', 'internal_api': 'openblas', 'prefix': 'libopenblas', 'filepath': '/home/ray/anaconda3/lib/python3.10/site-packages/numpy.libs/libopenblas64_p-r0-15028c96.3.21.so', 'version': '0.3.21', 'threading_layer': 'pthreads', 'architecture': 'SkylakeX', 'num_threads': 36}]
—
Reply to this email directly, view it on GitHub
<#132>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAZKZ6JLS37QPA26AZP5GBTWSNRKJANCNFSM6AAAAAAT3TNM4M>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
edited, Thanks for explaining. I still see 36 system threads reported by
#!/usr/bin/env python3
from threadpoolctl import threadpool_limits, threadpool_info
import psutil
import os
proc = psutil.Process(os.getpid())
print('pid', os.getpid())
print('threads:', len(proc.threads()))
print(threadpool_info())
import numpy
print('numpy imported')
with threadpool_limits(limits=1, user_api='blas'):
# Reload in case there is caching of proc.threads
proc = psutil.Process(os.getpid())
print('threads:', len(proc.threads()))
print(threadpool_info())
print('threads:', len(proc.threads()))
print(threadpool_info()) |
I am actually not sure how the system threads are managed so it is not so surprising to still see them and as threads a low weights objects, this should not reduce performances. |
Ok thanks! |
Hi, thanks for the work on this package! I would like to use it but I am not getting the expected behavior.
When I import
numpy
inside athreadpool_limits
context manager, I expect the number of threads to be limited bythreadpool_limits
.What happens is that the thread count is not changed.
Is this user error or a bug?
The text was updated successfully, but these errors were encountered: