简体   繁体   English

Python traceback.format_tb 在 Cython 扩展编译后无法完全工作

[英]Python traceback.format_tb doesn't work completely after Cython Extension compiled

  • Python version: 3.7 Python 版本:3.7
  • Cython version: 0.29.15 Cython 版本:0.29.15

source code: example/example.py源代码: example/example.py

import traceback


def run():
    try:
        assert 1 == 0
    except Exception as e:
        log_info = f'Erase failed, exception={type(e).__name__},\n{e},\n{"".join(traceback.format_tb(e.__traceback__))}'
        print('*********************')
        print(log_info)
        print('*********************')

setup.py

from setuptools import setup
from setuptools.extension import Extension
from Cython.Build import cythonize

setup(name='example',
      version="0.0",
      ext_modules=cythonize(
          [
              Extension("example.*", ["example/**/*.py"]),
          ],
          build_dir="build",
          compiler_directives=dict(always_allow_keywords=True,
                                   language_level='3')))

Build command: python setup.py build构建命令: python setup.py build

Output before compiled Output 编译前

*********************
Erase failed, exception=AssertionError,
,
  File "example/example.py", line 6, in run
    assert 1 == 0
*********************

Ouput after compiled编译后的输出

*********************
Erase failed, exception=AssertionError,
,
  File "example/example.py", line 6, in example.example.run

*********************

This is expected, as there's no Python code to refer to anymore after Cython transpiles your code to C and compiles the native module.这是意料之中的,因为在 Cython 将您的代码转换为 C 并编译本机模块后,不再需要参考 Python 代码。

The issue https://github.com/cython/cython/issues/1755 is related, but it's also been open for 3+ years.问题https://github.com/cython/cython/issues/1755是相关的,但它也已经开放了 3 年以上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM