-
Notifications
You must be signed in to change notification settings - Fork 125
Remove PyArrayModule #62
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
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.
Great work 👍
This matches the PyO3 way well.
src/npyffi/array.rs
Outdated
unsafe { | ||
PyArray_Type_Ptr = mod_.get_type_object(ArrayType::PyArray_Type); | ||
// TODO: this operation is 'mostly safe' because of GIL, but not completely thread safe |
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.
Do you have any plan to fix it?
I try to use lazy_static and Mutex, but it (9bd4376) does not work :<
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.
Somewhat calling python ffi from a synchronized path causes dead lock when cargo test
executes multiple tests in parallel.
But I think we can ensure safety of substitution to ARRAY_API_CACHE by std::sync::Once
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.
i.e.
This is OK
let api = get_numpy_api(MOD_NAME, CAPSULE_NAME);
INIT_API.call_once(move || {
ARRAY_API_CACHE = PyArrayAPI_Inner(api);
});
but this causes dead lock, in parallel tests
INIT_API.call_once(move || {
let api = get_numpy_api(MOD_NAME, CAPSULE_NAME);
ARRAY_API_CACHE = PyArrayAPI_Inner(api);
});
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.
And I think we don't have to use Mutex
.
We have to lock the access to Numpy API only once in a program, since Numpy API is pinned by capsule.
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.
It seems to be correct.
Thanks for review, I synchronized the substitution to static. |
The parallel test by |
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.
LGTM
and use static variable to access Numpy C APIs.
Since nowt we can't ensure operation's safety by
PyArrayModule
's lifetime, I changed all APIs to return or take&'py PyArray
.TODO: