Skip to content

Commit

Permalink
Merge branch 'master' into strict_internal_nursery_in_start
Browse files Browse the repository at this point in the history
  • Loading branch information
jakkdl authored Jan 30, 2024
2 parents 0ce52c1 + 7cb15ea commit 03fee26
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
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 @@ def darwin_namefunc(
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"

# 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 @@ def _get_thread_name(ident: int | None = None) -> str | None:

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"
try:
libpthread = ctypes.CDLL(libpthread_path)
except Exception:
print(f"no pthread on {sys.platform}")
return None
libpthread = ctypes.CDLL(libpthread_path)

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

Expand Down

0 comments on commit 03fee26

Please sign in to comment.