Repository navigation
Isolate the _datetime extension module #117398
Copy link
Copy link
Closed
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtopic-subinterpreterstype-featureA feature request or enhancementA feature request or enhancement
Description
Feature or enhancement
Proposal:
I hope this issue will complete _datetime isolation.
My concerns (and answers)
-
Py_MOD_PER_INTERPRETER_GIL_SUPPORTEDshould be applied in sync with_zoninfo?- YES: Possible.
-
Can a module state have a C-API structure, keeping a capsule just for comatibility?
- NO: Possible, but a user should not touch the module state.
-
C-API supports only the main interpreter? Otherwise,
PyInterpreterStateis acceptable to point each structure?- NO:
PyDateTimeAPIcannot emit an error. Also, noPyInterpreterStatemember is accessible fromdatetime.h. UPDATE: Seems to be possible by using a global function pointer instead of a function.
- NO:
Specific issue:
Links to previous discussion of this feature:
- Isolate Stdlib Extension Modules #103092
- gh-71587: Isolate
_datetime#102995 - gh-71587: Establish global state in
_datetime#110475
Linked PRs (closed)
Details
Linked PRs
- gh-117398: Isolate _datetime (3.13.0a6 PoC) #117498
- gh-117398: Isolate _datetime (3.13.0a6 PoC) with AC #118337
- gh-117398: Move types to datetime state #118606
- gh-117398: Add multiphase support to _datetime #119373
- gh-117398: Statically Allocate the Datetime C-API #119472
- gh-117398: Add datetime C-API type check test for subinterpreters #119604
- [3.13] gh-117398: Add multiphase support to _datetime (gh-119373) #119636
- gh-117398: Convert datetime.IsoCalendarDate To A Heap Type #119637
- [3.13] gh-117398: Revert gh-119636, Add multiphase support to _datetime #119639
- gh-117398: Add datetime Module State #119640
- [3.13] gh-117398: Statically Allocate the Datetime C-API (GH-119472) #119641
- gh-117398: gh-119655: datetime: Init static state once & don't free it #119662
- [3.13] gh-117398: Add multiphase support to _datetime #119694
- [3.13] gh-117398: Convert datetime.IsoCalendarDate To A Heap Type (gh-119637) #119695
- gh-117398: Add datetime Module State #119810
- gh-117398: Use Per-Interpreter State for the _datetime Static Types #119929
- [3.13] gh-117398: Add datetime Module State (gh-119810) #120004
- [3.13] gh-117398: Use Per-Interpreter State for the _datetime Static Types (gh-119929) #120009
- gh-71587: Drop local reference cache to
_strptimemodule in_datetime#120224 - [3.13] gh-117398: Add datetime C-API type check test for subinterpreters (gh-119604) #120463
- gh-117398: Use the correct module loader for iOS in datetime CAPI test. #120477
- [3.13] gh-117398: Use the correct module loader for iOS in datetime CAPI test (GH-120477) #121561
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtopic-subinterpreterstype-featureA feature request or enhancementA feature request or enhancement
Projects
- StatusShow more project fieldsDone
Activity
neonene commentedon Mar 31, 2024
PR #117399 fails except Windows. Is there an easy way to access a
PyInterpreterStatemember? I'll try later allowing C-API only for the main-interpreter with a global variable.erlend-aasland commentedon Mar 31, 2024
I briefly discussed the C API capsule with @pganssle on the 2023 (or was it 2022?) language summit. I also asked the Steering Council to comment about backwards compatibility concerns regarding datetime.h (which is not included by Python.h):
Putting it in the
PyInterpreterStatestruct is an option, but I'm not sure how much we want to bloat that struct. We probably want to deprecate the current capsulated API and introduce a new capsulated API.pythongh-117398: Move types to datetime state
pythongh-117398: Move types to datetime state
vstinner commentedon May 5, 2024
Converting the _datetime extension to multiphase initialization and/or converting static types to heap types is complicated because:
<Include/datetime.h>C APIPyDateTime_Check()fails and everything else fails.It reminds me the very complicated case of the PyAST C API. We managed to convert the _ast extension to heap types and multiphase init by moving state to the interpreter state. Other "trade offs" attemps for the _ast extension ended by introducing crashes which were hard to trigger and hard to fix.
So I propose this plan to isolate the datetime module:
neonene commentedon May 5, 2024
Where can we see your rationale for the inflating
PyInterpreterStatewith PyAST C-API? IIUC, the practice is supposed to be bad: #103092 (comment).How do you associate the PyAST issue with PyDateTime in terms of the mechanizm and impact?
@encukou, @ericsnowcurrently
vstinner commentedon May 6, 2024
Both provide a C API and we wanted to isolate their C extension.
I will try to dig into the bug tracker later. In short, there were 2-3 crashes related to the isolation of the _ast extension. Crashes related to the C API.
pythongh-117398: Move types to datetime state
neonene commentedon May 10, 2024
Python-ast.c(3.10.0 alpha 0: b1cc6ba)Previously,
PyAST_Check()imported the_astmodule throughget_global_ast_state(). The implicit import could get an unsafe pseudo module by replacing__import__()with a lazy import (strongly discouraged since Python 3.3).datetime.hPyDate_Check()requires the real module to be imported in advance by callingPyCapsule_Import()explicitly.At least, the regression case in PyAST C-API above cannot be applied to PyDateTime C-API, I think.
pythongh-117398: Move types to datetime state
62 remaining items
pythongh-117398: Use the correct module loader for iOS in datetime CA…
[3.13] gh-117398: Use the correct module loader for iOS in datetime C…
pythongh-117398: Convert datetime.IsoCalendarDate To A Heap Type (pyt…
pythongh-117398: Add datetime Module State (pythongh-119810)
pythongh-117398: Use Per-Interpreter State for the _datetime Static T…
pythongh-117398: Add datetime C-API type check test for subinterprete…
pythongh-117398: Use the correct module loader for iOS in datetime CA…
pythongh-117398: Statically Allocate the Datetime C-API (pythonGH-119472
pythongh-117398: Add multiphase support to _datetime (pythongh-119373)
pythongh-117398: pythongh-119655: datetime: Init static state once & …
pythongh-117398: Convert datetime.IsoCalendarDate To A Heap Type (pyt…
pythongh-117398: Add datetime Module State (pythongh-119810)
pythongh-117398: Use Per-Interpreter State for the _datetime Static T…
pythongh-117398: Add datetime C-API type check test for subinterprete…
pythongh-117398: Use the correct module loader for iOS in datetime CA…