Skip to content

Commit a9e6276

Browse files
committed
log warning on ctypes load error, adapted from ahupp#279
1 parent 339eac0 commit a9e6276

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

magic/loader.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import sys
44
import glob
55
import os.path
6+
import logging
67

8+
logger = logging.getLogger(__name__)
79

810
def _lib_candidates_linux():
911
"""Yield possible libmagic library names on Linux.
@@ -61,11 +63,15 @@ def _lib_candidates():
6163
def load_lib():
6264
for lib in _lib_candidates():
6365
# find_library returns None when lib not found
64-
if lib:
65-
try:
66-
return ctypes.CDLL(lib)
67-
except OSError:
68-
pass
66+
if lib is None:
67+
continue
68+
if not os.path.exists(lib):
69+
continue
70+
71+
try:
72+
return ctypes.CDLL(lib)
73+
except OSError:
74+
logger.warning("Failed to load: " + lib, exc_info=True)
6975

7076
# It is better to raise an ImportError since we are importing magic module
7177
raise ImportError("python-magic: failed to find libmagic. Check your installation")

0 commit comments

Comments
 (0)