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
Remove redundant gil acquisition. #9133
Conversation
Looks like the previous |
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.
like @rth pointed out, we need a test to see if this works without hiccups when self.func
is a python object.
Additionally we also need a test to see if TypeError
gets raised properly
sklearn/neighbors/dist_metrics.pyx
Outdated
# if d is the wrong type. | ||
return d | ||
except TypeError: | ||
raise TypeError("Custom distance function must accept two " |
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.
When you raise a python error, you need the gil.
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.
Ah the function is defined with gil
but isn't it the default mode. I'm not sure why we are defining it with gil
.
Ah it's @robertwd from cython ;) I'll let you handle this. Could you kindly update the PR description so we understand your PR better? |
Hmm... there's something odd here with the inline method being declared "with gil" which should make the inner one redundant. Another try. |
@robertwb I get a compilation error with 0.26b0 (see #9272 (comment)) which I think is exactly related to this PR. Have you managed to get to the bottom of this ? |
Just also ran into this. Looks like we are both planning to release, we should fix this... |
Just to summarize a bit the code base. There is the base class |
The final change looks right to me. If all methods in the hierarchy are declared with the same |
Regarding the compile failure due to Python object variables being used, I guess you'd have to hack in a call to a new ( Note that this is only needed for compatibility with older Cython versions, as the latest should support the |
It was looking like a bug. Thanks for the hack. I'll try that. edit: It seems to work ;) |
Fixed in #9311 |
Reference Issue
What does this implement/fix? Explain your changes.
Any other comments?