Skip to content

ctypes should have an option to *not* catch c++ exceptions #156206

Description

@jackjansen

Feature or enhancement

Proposal:

The ctypes module catches native exceptions and turns them into Python exceptions. In 99.99% of the cases this is exactly what you want, as a Python developer.

But the exception (pun unintended) is when the native exception is repeatable, but only happens in situations where you have no control.

An example is native exceptions that only occur when running your Python code which depends on numerous native libraries on the GitHub Windows runner. I have just had this happen to me for the third time in a couple of years. In the previous two cases the problem was some Python package (or native package it depends on) having a private copy of an outdated MSVC runtime library (or depending on some outdated copy). This is impossible to trace, because it is not repeatable on a development machine, and it isn't even repeatable when capturing the built folder and running the tests on you development machine.

Some mechanism (either a global method in ctypes to disable the exception-catching, or an environment variable PYTHON_CTYPES_DONT_CATCH_EXCEPTIONS) would help immensely, because I could use a debugging Python and a stack trace to pinpoint where the exception happens.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions