我正在尝试使用distutils.core.setup编译一些cython代码文件,以防止编译崩溃,但为了尽可能地继续,我将每个文件扩展名放在一个try语句中
from distutils.core import setup, Extension
from Cython.Build import cythonize
from Cython.Distutils import build_ext
import numpy as np
pyx = [#file 1
Extension('file1',
include_dirs=[np.get_include()],
sources ["file1.pyx"]),
#file 2
Extension('file2',
include_dirs=[np.get_include()],
language="c",
sources = ["file2.pyx"]),
#rest of files
]
# compile extensions
for E in pyx :
try:
setup( ext_modules = [E], cmdclass={'build_ext': build_ext})
except Exception as e:
print "THIS IS AN ERROR", e一切都工作得很好,除非出现错误,try和catch似乎没有用。编译将停止,不执行except语句。
你知道为什么要做什么吗?
发布于 2016-06-04 03:33:52
SystemExit必须包含在except中
# compile extensions
for E in pyx :
try:
setup( ext_modules = [E], cmdclass={'build_ext': build_ext})
except (Exception, SystemExit) as e:
print "THIS IS AN ERROR", ehttps://stackoverflow.com/questions/37617626
复制相似问题