Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork10.9k
GH-29021: Convert umath_linalg to multi-phase init (PEP 489)#29030
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 ourterms of service andprivacy 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 fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -4688,57 +4688,40 @@ static PyMethodDef UMath_LinAlgMethods[] = { | ||||||
{NULL,NULL,0,NULL}/* Sentinel */ | ||||||
}; | ||||||
staticint | ||||||
_umath_linalg_exec(PyObject*m) | ||||||
{ | ||||||
PyObject*d; | ||||||
PyObject*version; | ||||||
import_array1(-1); | ||||||
import_umath1(-1); | ||||||
d=PyModule_GetDict(m); | ||||||
if (d==NULL) { | ||||||
return-1; | ||||||
} | ||||||
version=PyUnicode_FromString(umath_linalg_version_string); | ||||||
if (version==NULL) { | ||||||
return-1; | ||||||
} | ||||||
intret=PyDict_SetItemString(d,"__version__",version); | ||||||
Py_DECREF(version); | ||||||
if (ret<0) { | ||||||
return-1; | ||||||
} | ||||||
/* Load the ufunc operators into the module's namespace */ | ||||||
if (addUfuncs(d)<0) { | ||||||
return-1; | ||||||
} | ||||||
#ifPY_VERSION_HEX<0x30d00b3&& !HAVE_EXTERNAL_LAPACK | ||||||
lapack_lite_lock=PyThread_allocate_lock(); | ||||||
if (lapack_lite_lock==NULL) { | ||||||
PyErr_NoMemory(); | ||||||
return-1; | ||||||
} | ||||||
#endif | ||||||
@@ -4748,10 +4731,30 @@ PyMODINIT_FUNC PyInit__umath_linalg(void) | ||||||
PyDict_SetItemString(d,"_ilp64",Py_False); | ||||||
#endif | ||||||
return0; | ||||||
} | ||||||
staticstructPyModuleDef_Slot_umath_linalg_slots[]= { | ||||||
{Py_mod_exec, (void*)_umath_linalg_exec}, | ||||||
#ifPY_VERSION_HEX >=0x030c00f0// Python 3.12+ | ||||||
{Py_mod_multiple_interpreters,Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED}, | ||||||
#endif | ||||||
#ifPY_VERSION_HEX >=0x030d00f0// Python 3.13+ | ||||||
// signal that this module supports running without an active GIL | ||||||
{Py_mod_gil,Py_MOD_GIL_NOT_USED}, | ||||||
#endif | ||||||
{0,NULL}, | ||||||
}; | ||||||
staticstructPyModuleDefmoduledef= { | ||||||
PyModuleDef_HEAD_INIT,/* m_base */ | ||||||
"_umath_linalg",/* m_name */ | ||||||
NULL,/* m_doc */ | ||||||
0,/* m_size */ | ||||||
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. For now, in a future PR this can be changed. Suggested change
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. See also my note in#29025 (comment). Briefly, I was mistaken in my understanding of the documentation, The safest thing reinitialisation-wise would be to use themultiple interpreter opt-out suggested by CPython. This would enforce that each extension module is only imported & initialised once per process. However, this causes cc@encukou re the best way to do a gradual migration to multi-phase In the case of 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. I'vejust updated the HOWTO, seehere before it gets to main docs. Basically, to allow re-import, clear the "loaded" flag in The PyMutex stuff in the updated HOWTO is 3.13+ non-limited API, but isn't necessary in the medium term (on CPython you're protected by the GIL; even free-threading builds use an import lock which isn't likely to go away). For the long-term (or alternate CAPI implementations) you could add no-op shims. The 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.
I am not opposed to breaking the test/changing the behavior. The ask would be to summarize how things change for:
| ||||||
UMath_LinAlgMethods,/* m_methods */ | ||||||
_umath_linalg_slots,/* m_slots */ | ||||||
}; | ||||||
PyMODINIT_FUNCPyInit__umath_linalg(void) { | ||||||
returnPyModuleDef_Init(&moduledef); | ||||||
} |
Uh oh!
There was an error while loading.Please reload this page.