From 1746dc00dfc86f55e85df45a0553731a51e6175f Mon Sep 17 00:00:00 2001 From: Daniel Ching Date: Fri, 16 Sep 2022 12:02:09 -0500 Subject: [PATCH 1/4] BUG: Allow finding sharedlibs when path is not absolute --- source/tomopy/util/extern/__init__.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/source/tomopy/util/extern/__init__.py b/source/tomopy/util/extern/__init__.py index 79cb809ea..80e4e7148 100644 --- a/source/tomopy/util/extern/__init__.py +++ b/source/tomopy/util/extern/__init__.py @@ -58,16 +58,21 @@ def c_shared_lib(lib_name, error=True): The ctypes.util.find_library function preprends "lib" to the name. """ - load_dll = ctypes.cdll.LoadLibrary - ext = '.so' - if sys.platform == 'darwin': - ext = '.dylib' if os.name == 'nt': - ext = '.dll' load_dll = ctypes.windll.LoadLibrary + else: + load_dll = ctypes.cdll.LoadLibrary + + # Returns None or a library name sharedlib = ctypes.util.find_library(lib_name) - if sharedlib and os.path.exists(sharedlib): - return load_dll(sharedlib) + + if sharedlib is not None: + try: + # No error if sharedlib is None; error if library name wrong + return load_dll(sharedlib) + except OSError: + pass + explanation = ( 'TomoPy links to compiled components which are installed separately' ' and loaded using ctypes.util.find_library().' @@ -79,7 +84,8 @@ def c_shared_lib(lib_name, error=True): warnings.warn( explanation + 'Some functionality is unavailable because an optional shared' - f' library, {sharedlib}, is missing.', ImportWarning) + f' library, {lib_name}, is missing.', ImportWarning) + return None def _missing_library(function): From e21df35259de7ccb53cebfef72d0a4799c59e156 Mon Sep 17 00:00:00 2001 From: Daniel Ching Date: Fri, 16 Sep 2022 13:01:53 -0500 Subject: [PATCH 2/4] BUG: Remove bare exceptions --- source/tomopy/util/mproc.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/tomopy/util/mproc.py b/source/tomopy/util/mproc.py index 406361ffd..ab8f780f1 100644 --- a/source/tomopy/util/mproc.py +++ b/source/tomopy/util/mproc.py @@ -87,7 +87,7 @@ def get_rank(): from mpi4py import MPI comm_w = MPI.COMM_WORLD return comm_w.Get_rank() - except: + except ModuleNotFoundError: return 0 @@ -97,7 +97,7 @@ def get_nproc(): from mpi4py import MPI comm_w = MPI.COMM_WORLD return comm_w.Get_size() - except: + except ModuleNotFoundError: return 1 def barrier(): @@ -106,7 +106,7 @@ def barrier(): from mpi4py import MPI comm_w = MPI.COMM_WORLD comm_w.Barrier() - except: + except ModuleNotFoundError: pass From f512c904b643cacbd0d1598d499cee465ee78ada Mon Sep 17 00:00:00 2001 From: Daniel Ching Date: Fri, 16 Sep 2022 13:02:37 -0500 Subject: [PATCH 3/4] BUG: Check threadpool for exceptions --- source/tomopy/recon/algorithm.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/source/tomopy/recon/algorithm.py b/source/tomopy/recon/algorithm.py index d2992013f..ecf844657 100644 --- a/source/tomopy/recon/algorithm.py +++ b/source/tomopy/recon/algorithm.py @@ -439,9 +439,15 @@ def _dist_recon(tomo, center, recon, algorithm, args, kwargs, ncore, nchunk): else: # execute recon on ncore threads with cf.ThreadPoolExecutor(ncore) as e: - for slc in use_slcs: + futures = [ e.submit(algorithm, tomo[slc], center[slc], recon[slc], - *args, **kwargs) + *args, **kwargs) for slc in use_slcs + ] + done, _ = cf.wait(futures, return_when=cf.ALL_COMPLETED) + for f in done: + if f.exception() is not None: + raise f.exception() + if pythreads is not None: # reset to default From a969ea282c89339eaa48141a9c11be041b6a2332 Mon Sep 17 00:00:00 2001 From: Daniel Ching Date: Fri, 16 Sep 2022 17:43:13 -0500 Subject: [PATCH 4/4] Limit opencv version for Windows --- envs/win-37.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/envs/win-37.yml b/envs/win-37.yml index 904389d6a..8e5e4a038 100644 --- a/envs/win-37.yml +++ b/envs/win-37.yml @@ -22,5 +22,5 @@ dependencies: - mkl - mkl-devel - mkl_fft - - opencv>=3.4 + - opencv>=3.4,<4.2 - pytest