Skip to content

Importing module with capsule attribute fails in sub interpreter#112100

@tonybaloney

Description

@tonybaloney

Bug report

Bug description:

When importing certain modules (zoneinfo is an example), attributes are missing when inside a sub interpreter.

Importing these modules works inside the main interpreter.

I've written a test to demonstrate the bug

importunittestimport_xxsubinterpretersasinterpretersclassTestCapsule(unittest.TestCase): deftest_capsule(self): importzoneinfodeftest_capsule_in_sub_interpreter(self): interp=interpreters.create() interpreters.run_string(interp, "import zoneinfo")
.Traceback (most recent call last): File "<string>", line 1, in <module> File "/usr/local/lib/python3.13/zoneinfo/__init__.py", line 14, in <module> from _zoneinfo import ZoneInfo AttributeError: module 'datetime' has no attribute 'datetime_CAPI' E ====================================================================== ERROR: test_capsule_in_sub_interpreter (test_capsule.TestCapsule.test_capsule_in_sub_interpreter) ---------------------------------------------------------------------- Traceback (most recent call last): File "/Users/anthonyshaw/projects/subinterpreter-web/test_capsule.py", line 12, in test_capsule_in_sub_interpreter interpreters.run_string(interp, "import zoneinfo") _xxsubinterpreters.RunFailedError: AttributeError: module 'datetime' has no attribute 'datetime_CAPI' ---------------------------------------------------------------------- Ran 2 tests in 0.457s FAILED (errors=1) 

I haven't seen this behaviour on any other modules, the thing that seemed special with datetime and this attribute is that it is a PyCapsule. So the issue is likely related to that?

CPython versions tested on:

3.13, CPython main branch

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirpendingThe issue will be closed if no feedback is providedtopic-subinterpreterstype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions