-
-
Notifications
You must be signed in to change notification settings - Fork 11k
MAINT: Convert multiarray to multi-phase init (PEP 489) #29022
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
Conversation
1c01323
to
4e8bb3c
Compare
The failures here are (will be) as the relevant parts of The other option is to keep treating those variables as global and instead re-add the same object to the new module. This may cause other problems though, as I don't believe it's the intended execution model. There also appears to be a SIGSEV around the call to cc @ngoldbaum if you'd be able to suggest anything? A |
760440b
to
f5eed00
Compare
Nice, will be great to make progress here! We have a lot of global state, but much of it can probably just stay intact within the same interpreter (some cannot, e.g. because new singletons are created but this was always incorrect, so for a first start...). So without multi-stage init, CPython would not run the module initially again if the so was already loaded (so deleting it from One problem with There is a check to catch types that are set to bad values, I honestly don't remember why it is there, and the loop definitely looks bad (it should just look up the type number of them So long we don't actually support subinterpreters, the old type object should actually be good to use. @AA-Turner maybe you can try applying something like this: diff --git a/numpy/_core/src/multiarray/dtypemeta.c b/numpy/_core/src/multiarray/dtypemeta.c
index 0b1b0fb391..adb268097c 100644
--- a/numpy/_core/src/multiarray/dtypemeta.c
+++ b/numpy/_core/src/multiarray/dtypemeta.c
@@ -1075,6 +1075,11 @@ dtypemeta_wrap_legacy_descriptor(
_PyArray_LegacyDescr *descr, PyArray_ArrFuncs *arr_funcs,
PyTypeObject *dtype_super_class, const char *name, const char *alias)
{
+ if (Py_TYPE(descr) != NULL && NPY_DTYPE(descr)->singleton == (PyArray_Descr *)descr) {
+ /* We seem to already have created a type, multiple inits? */
+ return 0;
+ }
+
int has_type_set = Py_TYPE(descr) == &PyArrayDescr_Type;
if (!has_type_set) { (but there will likely be a long tail of these type of things, and of course the real fix will be to move the singletons into proper module state!) |
0683e1d
to
c7378be
Compare
|
Yeah we get spurious failures due to network issues quite a bit, safe to ignore. Also, wow, awesome, all the CI passes otherwise 🎉 |
Before this is merged, one question. I've had to change Lines 53 to 77 in 3363b38
Is it worth adding a special case for where we detect re-initialisation? I've not done so currently because it is less work, but I'd be remiss for not asking. A |
Would be nice to avoid printing out that monster if it isn't too hard, considering that it is -- for once -- really unrelated. |
c7378be
to
67034c7
Compare
I've updated A |
return 0; | ||
|
||
err: | ||
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.
Not a big thing, but can you just remove the err
label? No point in using goto err
if there is no cleanup needed.
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.
Done; I avoided doing so in the first instance as it makes the diff much larger.
67034c7
to
d4b3f9b
Compare
Uh oh!
There was an error while loading. Please reload this page.