-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
gh-136421: Fix crash when _datetime is been initialized in multiple sub-interpreters #136422
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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. |
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -7344,9 +7344,13 @@ 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); | ||||||||||||||||||
PyMutex_Unlock(&mutex); | ||||||||||||||||||
Comment on lines
+7350
to
+7352
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A lock needs to be applied to whole the loop or function rather than to a type to avoid a crash here (for me), because all managed static extension types are currently supposed to be indexed by using the same interpreter: Lines 322 to 329 in db47f4d
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Hmm, still crashes with many workers... |
||||||||||||||||||
if (ret < 0) { | ||||||||||||||||||
return -1; | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the assumption is that this can run concurrently, then we need to also protect the assignments to
tp_base
above.