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 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 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): 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