More precise exceptions

This commit is contained in:
Biryuzovye Kleshni 2018-06-23 10:32:05 +00:00
parent a181da3632
commit 079326bc03
3 changed files with 21 additions and 9 deletions

View File

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

View File

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

View File

@ -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])