Improved library loading a bit (#3481)

* Improved library loading a bit

* Fixed indentation.

* Fixes according to the discussion

* Moved the comment to a separate line.
* specified exception type
This commit is contained in:
KOLANICH 2018-07-20 23:03:44 +00:00 committed by Philip Hyunsu Cho
parent 8e90b60c4d
commit a393d44c5d

View File

@ -114,10 +114,17 @@ def _get_log_callback_func():
def _load_lib():
"""Load xgboost Library."""
lib_path = find_lib_path()
if len(lib_path) == 0:
lib_paths = find_lib_path()
if len(lib_paths) == 0:
return None
lib = ctypes.cdll.LoadLibrary(lib_path[0])
pathBackup = os.environ['PATH']
for lib_path in lib_paths:
try:
# needed when the lib is linked with non-system-available dependencies
os.environ['PATH'] = pathBackup + os.pathsep + os.path.dirname(lib_path)
lib = ctypes.cdll.LoadLibrary(lib_path)
except OSError:
continue
lib.XGBGetLastError.restype = ctypes.c_char_p
lib.callback = _get_log_callback_func()
if lib.XGBRegisterLogCallback(lib.callback) != 0: