Skip to content
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

Fix finding pthread_*name_np on vanilla musl libc #2939

Merged
merged 1 commit into from
Jan 30, 2024
Merged
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
1 change: 1 addition & 0 deletions newsfragments/2939.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The pthread functions are now correctly found on systems using vanilla versions of musl libc.
9 changes: 7 additions & 2 deletions src/trio/_core/_thread_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@
setname(_to_os_thread_name(name))

# find the pthread library
# this will fail on windows
# this will fail on windows and musl
libpthread_path = ctypes.util.find_library("pthread")
if not libpthread_path:
return None
# musl includes pthread functions directly in libc.so
# (but note that find_library("c") does not work on musl,
# see: https://github.com/python/cpython/issues/65821)
# so try that library instead
# if it doesn't exist, CDLL() will fail below
libpthread_path = "libc.so"

Check warning on line 52 in src/trio/_core/_thread_cache.py

View check run for this annotation

Codecov / codecov/patch

src/trio/_core/_thread_cache.py#L52

Added line #L52 was not covered by tests

# Sometimes windows can find the path, but gives a permission error when
# accessing it. Catching a wider exception in case of more esoteric errors.
Expand Down
12 changes: 10 additions & 2 deletions src/trio/_tests/test_threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,17 @@

libpthread_path = ctypes.util.find_library("pthread")
if not libpthread_path:
print(f"no pthread on {sys.platform})")
# musl includes pthread functions directly in libc.so
# (but note that find_library("c") does not work on musl,
# see: https://github.com/python/cpython/issues/65821)
# so try that library instead
# if it doesn't exist, CDLL() will fail below
libpthread_path = "libc.so"

Check warning on line 245 in src/trio/_tests/test_threads.py

View check run for this annotation

Codecov / codecov/patch

src/trio/_tests/test_threads.py#L245

Added line #L245 was not covered by tests
try:
libpthread = ctypes.CDLL(libpthread_path)
except Exception:
print(f"no pthread on {sys.platform}")

Check warning on line 249 in src/trio/_tests/test_threads.py

View check run for this annotation

Codecov / codecov/patch

src/trio/_tests/test_threads.py#L248-L249

Added lines #L248 - L249 were not covered by tests
return None
libpthread = ctypes.CDLL(libpthread_path)

pthread_getname_np = getattr(libpthread, "pthread_getname_np", None)

Expand Down
Loading