Skip to content

Commit 3a6f844

Browse files
authored
Fix crash
1 parent 7d85f55 commit 3a6f844

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Modules/_datetimemodule.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7335,6 +7335,11 @@ init_static_types(PyInterpreterState *interp, int reloading)
73357335
if (reloading) {
73367336
return 0;
73377337
}
7338+
if (_Py_IsMainInterpreter(interp)
7339+
&& PyType_HasFeature(&PyDateTime_DateType, Py_TPFLAGS_READY)) {
7340+
// This function was already called from PyInit__datetime()
7341+
return 0;
7342+
}
73387343

73397344
// `&...` is not a constant expression according to a strict reading
73407345
// of C standards. Fill tp_base at run-time rather than statically.
@@ -7564,6 +7569,11 @@ static PyModuleDef datetimemodule = {
75647569
PyMODINIT_FUNC
75657570
PyInit__datetime(void)
75667571
{
7572+
PyInterpreterState *interp = PyInterpreterState_Get();
7573+
// gh-136421: Ensure static types are fully finalized at the shutdown of
7574+
// the main interpreter rather than subinterpreters for concurrency.
7575+
assert(_Py_IsMainInterpreter(interp));
7576+
init_static_types(interp, 0);
75677577
return PyModuleDef_Init(&datetimemodule);
75687578
}
75697579

0 commit comments

Comments
 (0)