diff --git a/src/workprover/__init__.py b/src/workprover/__init__.py index d7cd34ac..2394af8f 100644 --- a/src/workprover/__init__.py +++ b/src/workprover/__init__.py @@ -47,12 +47,12 @@ class WorkProver(threading.Thread): try: self.availableSolvers["fast"] = fastsolver.FastSolver(codePath) - except: + except fastsolver.FastSolverError: pass try: self.availableSolvers["gpu"] = gpusolver.GPUSolver(codePath, GPUVendors) - except: + except gpusolver.GPUSolverError: pass try: diff --git a/src/workprover/fastsolver.py b/src/workprover/fastsolver.py index b443aa0c..36477678 100644 --- a/src/workprover/fastsolver.py +++ b/src/workprover/fastsolver.py @@ -4,6 +4,9 @@ import platform import subprocess import ctypes +class FastSolverError(Exception): + pass + def loadFastSolver(codePath): if hasattr(sys, "winver"): suffix = "-32" @@ -13,7 +16,10 @@ def loadFastSolver(codePath): path = os.path.join(codePath, "fastsolver/libfastsolver{}.dll".format(suffix)) - return ctypes.WinDLL(path) + try: + return ctypes.WinDLL(path) + except: + raise FastSolverError() makePath = os.path.join(codePath, "fastsolver") path = os.path.join(codePath, "fastsolver/libfastsolver.so") @@ -21,12 +27,15 @@ def loadFastSolver(codePath): try: return ctypes.CDLL(path) except: - if not hasattr(sys, "frozen"): + if hasattr(sys, "frozen"): + raise FastSolverError() + + try: subprocess.call(["make", "-C", makePath]) return ctypes.CDLL(path) - else: - raise Exception() + except: + raise FastSolverError() class FastSolver(object): def __init__(self, codePath): diff --git a/src/workprover/gpusolver.py b/src/workprover/gpusolver.py index 59f56b04..ce258099 100644 --- a/src/workprover/gpusolver.py +++ b/src/workprover/gpusolver.py @@ -14,8 +14,11 @@ class GPUSolver(object): def __init__(self, codePath, vendors = None): global pyopencl, numpy - import pyopencl - import numpy + try: + import pyopencl + import numpy + except ImportError: + raise GPUSolverError() device = None @@ -30,7 +33,7 @@ class GPUSolver(object): break else: - raise Exception() + raise GPUSolverError() context = pyopencl.Context(devices = [device])