首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >python distutils try setup

python distutils try setup
EN

Stack Overflow用户
提问于 2016-06-03 22:57:50
回答 1查看 78关注 0票数 1

我正在尝试使用distutils.core.setup编译一些cython代码文件,以防止编译崩溃,但为了尽可能地继续,我将每个文件扩展名放在一个try语句中

代码语言:javascript
复制
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语句。

你知道为什么要做什么吗?

EN

回答 1

Stack Overflow用户

发布于 2016-06-04 03:33:52

SystemExit必须包含在except中

代码语言:javascript
复制
# 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", e
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37617626

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档