From 1687f5d5a891758f59dcbc4f4f0b57351aac7988 Mon Sep 17 00:00:00 2001 From: John Litborn <11260241+jakkdl@users.noreply.github.com> Date: Tue, 11 Jul 2023 23:48:48 +0200 Subject: [PATCH] fix PermissionError due to accessing pthreads upon importing trio (#2693) * fix PermissionError due to accessing pthreads upon importing trio * fix codecov * add newsfragment --- newsfragments/2688.bugfix.rst | 1 + trio/_core/_thread_cache.py | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 newsfragments/2688.bugfix.rst diff --git a/newsfragments/2688.bugfix.rst b/newsfragments/2688.bugfix.rst new file mode 100644 index 0000000000..95f16feff7 --- /dev/null +++ b/newsfragments/2688.bugfix.rst @@ -0,0 +1 @@ +Fix ``PermissionError`` when importing `trio` due to trying to access ``pthread``. diff --git a/trio/_core/_thread_cache.py b/trio/_core/_thread_cache.py index e570e8dead..cc272fc92c 100644 --- a/trio/_core/_thread_cache.py +++ b/trio/_core/_thread_cache.py @@ -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