More precise exceptions
This commit is contained in:
parent
a181da3632
commit
079326bc03
|
@ -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:
|
||||
|
|
|
@ -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))
|
||||
|
||||
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):
|
||||
|
|
|
@ -14,8 +14,11 @@ class GPUSolver(object):
|
|||
def __init__(self, codePath, vendors = None):
|
||||
global pyopencl, 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])
|
||||
|
||||
|
|
Reference in New Issue
Block a user