Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix a crash when ``_datetime`` is being imported in multiple
sub-interpreters at the same time.
7 changes: 6 additions & 1 deletion Modules/_datetimemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -7344,11 +7344,16 @@ init_static_types(PyInterpreterState *interp, int reloading)

/* Bases classes must be initialized before subclasses,
* so capi_types must have the types in the appropriate order. */
static PyMutex mutex = {0};
for (size_t i = 0; i < Py_ARRAY_LENGTH(capi_types); i++) {
PyTypeObject *type = capi_types[i];
if (_PyStaticType_InitForExtension(interp, type) < 0) {
PyMutex_Lock(&mutex);
int ret = _PyStaticType_InitForExtension(interp, type);
if (ret < 0) {
PyMutex_Unlock(&mutex);
return -1;
}
PyMutex_Unlock(&mutex);
}

return 0;
Expand Down
Loading