-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
gh-136421: Load _datetime
static types during interpreter initialization
#136583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
I have no idea if this will fix the Windows build, but let's hope.
My concern is unnecessarily losing portability between the builtin module and the non-builtin one. This PR avoids a crash not by locking but forcing the main interpreter initialize the PyMODINIT_FUNC
PyInit__datetime(void)
{
+ if (PyDateTime_DateType.tp_subclasses == NULL) {
+ PyInterpreterState *interp = PyInterpreterState_Get();
+ // main interp currently checks a module before subinterp imports
+ assert(_Py_IsMainInterpreter(interp));
+ init_static_types(interp, 0);
+ }
return PyModuleDef_Init(&datetimemodule);
} |
Hmm, that feels really hacky. I wouldn't call the movement of |
The crash can be avoided even on pure Python level, and managed static extsension types are already special only for
Not sure about disabling. On Windows, |
Right, there are several ways to fix this that work, but I'm trying to find the fix that is the most correct. Relying on implementation details like
We have to find a balance between correctness and simplicity, and I'm not yet sure which that is. |
This is at least a feature change more than a bug fix. |
Yeah, you're right. I'd be fine with a bandaid fix for 3.14 if you want to make a PR. The |
Still rough example, but checking During the |
_datetime
is a special module, because it's the only non-builtin C extension that contains static types. As such, it would initialize static types in the module's execution function, which can run concurrently. Since static type initialization is not thread-safe, this caused crashes. This fixes it by moving the initialization of_datetime
's static types to interpreter startup (where all other static types are initialized), which is already properly protected through other locks._datetime
in sub-interpreters in the same time may crash the process #136421