Skip to content

Commit

Permalink
fix PermissionError due to accessing pthreads upon importing trio (#2693
Browse files Browse the repository at this point in the history
)

* fix PermissionError due to accessing pthreads upon importing trio

* fix codecov

* add newsfragment
  • Loading branch information
jakkdl authored Jul 11, 2023
1 parent 6d71047 commit 1687f5d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions newsfragments/2688.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix ``PermissionError`` when importing `trio` due to trying to access ``pthread``.
9 changes: 8 additions & 1 deletion trio/_core/_thread_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@ def darwin_namefunc(
libpthread_path = ctypes.util.find_library("pthread")
if not libpthread_path:
return None
libpthread = ctypes.CDLL(libpthread_path)

# Sometimes windows can find the path, but gives a permission error when
# accessing it. Catching a wider exception in case of more esoteric errors.
# https://github.com/python-trio/trio/issues/2688
try:
libpthread = ctypes.CDLL(libpthread_path)
except Exception: # pragma: no cover
return None

# get the setname method from it
# afaik this should never fail
Expand Down

0 comments on commit 1687f5d

Please sign in to comment.