Skip to content

Commit f1e7225

Browse files
committed
Fix crash when _datetime is been initialized in multiple sub-interpreters
1 parent ba9c198 commit f1e7225

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a crash when :mod:`_datetime` is being initialized in multiple
2+
sub-interpreters at the same time.

Modules/_datetimemodule.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7344,11 +7344,16 @@ init_static_types(PyInterpreterState *interp, int reloading)
73447344

73457345
/* Bases classes must be initialized before subclasses,
73467346
* so capi_types must have the types in the appropriate order. */
7347+
static PyMutex mutex = {0};
73477348
for (size_t i = 0; i < Py_ARRAY_LENGTH(capi_types); i++) {
73487349
PyTypeObject *type = capi_types[i];
7349-
if (_PyStaticType_InitForExtension(interp, type) < 0) {
7350+
PyMutex_Lock(&mutex);
7351+
int ret = _PyStaticType_InitForExtension(interp, type);
7352+
if (ret < 0) {
7353+
PyMutex_Unlock(&mutex);
73507354
return -1;
73517355
}
7356+
PyMutex_Unlock(&mutex);
73527357
}
73537358

73547359
return 0;

0 commit comments

Comments
 (0)