Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 15 additions & 12 deletions tests/test_threadpoolctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,6 @@
)


def stdlib_dllist():
"""Return ctypes.util.dllist when _load_libraries would use it, else None."""
if sys.platform in ("linux", "emscripten"):
return None
try:
from ctypes.util import dllist
except ImportError:
return None
return dllist


def is_old_openblas(lib_controller):
# Possible bug in getting maximum number of threads with OpenBLAS < 0.2.16
# and OpenBLAS does not expose its version before 0.3.4.
Expand Down Expand Up @@ -1014,6 +1003,20 @@ def test_threadpool_controller_repeated_init():
ThreadpoolController()


@pytest.mark.skipif(
sys.platform not in ("win32", "darwin") or sys.version_info[:2] < (3, 14),
reason="ctypes.util.dllist is only available on Python 3.14+",
)
def test_dllist_used_on_windows_and_macos():
"""Python 3.14+ lists libraries with ctypes.util.dllist on Windows and macOS."""
calls = []
controller = ThreadpoolController._from_controllers([])
controller._find_libraries_with_python = calls.append
controller._load_libraries()
assert calls == [threadpoolctl.dllist]
assert threadpoolctl.dllist is not None


def test_dllist_oserror_emits_warning():
"""dllist listing failures warn instead of raising, so they can be reported."""

Expand Down Expand Up @@ -1087,7 +1090,7 @@ def test_windows_library_path_longer_than_max_path(tmp_path):

@pytest.mark.skipif(sys.platform != "win32", reason="Windows-only test")
@pytest.mark.skipif(
stdlib_dllist() is not None,
threadpoolctl.dllist is not None,
reason="Python 3.14+ dllist does not apply the internal path length limit",
)
def test_windows_library_path_exceeds_internal_limit(tmp_path, monkeypatch):
Expand Down
10 changes: 7 additions & 3 deletions threadpoolctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@
# builds (#225). dllist also uses dl_iterate_phdr internally (#239), which we
# already avoid on Linux via /proc/self/maps on older versions of Python.
dllist = None
if sys.platform != "emscripten" and (
# Python 3.15 doesn't have the CFUNCTYPE anymore:
sys.platform == "linux" and sys.version_info[:2] >= (3, 15)
if (
sys.platform != "emscripten"
and (
sys.platform != "linux"
# Python 3.15 doesn't have the CFUNCTYPE anymore:
or sys.version_info[:2] >= (3, 15)
)
):
try:
from ctypes.util import dllist
Expand Down
Loading