You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Importing module with capsule attribute fails in sub interpreter #112100
.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?
Activity
tonybaloney commentedon Nov 15, 2023
@ericsnowcurrently this is one of the issues I've found trying to run Django inside a sub interpreter
tonybaloney commentedon Nov 15, 2023
This is the specific line that's failing. https://github.com/python/cpython/blob/main/Modules/_zoneinfo.c#L2717
The
_zoneinfomodule runsPyDateTimeAPI = (PyDateTime_CAPI *)PyCapsule_Import(PyDateTime_CAPSULE_NAME, 0)which fails.There is no check for whether the datetime module has been imported and is initialised.
Eclips4 commentedon Nov 15, 2023
I'm not sure, but it's probably related to the fact that
_datetimeisn't isolated for subinterpreters yet: #102995.Eclips4 commentedon Nov 15, 2023
PyCapsule_Importimports the datetime module.tonybaloney commentedon Nov 15, 2023
Yep, looking at that PR and the related changes it would probably cause the behaviour I'm seeing in this test
ericsnowcurrently commentedon Jul 8, 2024
@tonybaloney, could you verify if this is still a problem in 3.13?
tonybaloney commentedon Jul 9, 2024
Just confirmed this test case was fixed since 3.13b1 (tested 3.13b3)
tm-jdelapuente commentedon Nov 18, 2024
Hey! To clarify, was this backported to a patch version in 3.12? I assume not - just checking
Eclips4 commentedon Nov 18, 2024
This wasn't backported because there was no fix 🙂
But if you're talking about datetime isolation, it wasn't backported to 3.12.