Skip to content

Conversation

@albanD
Copy link
Contributor

@albanD albanD commented Nov 1, 2022

Fix for #22507
This makes this deleter compliant with the proposal at dmlc/dlpack#103

@charris charris changed the title Ensure raw dlpack deleter works when called without the GIL MAINT: Ensure raw dlpack deleter works when called without the GIL Nov 1, 2022
// PyObjects stored in them after the Python runtime has already been
// terminated.
if (!Py_IsInitialized())
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add brackets (slight preference for /* style comments also).

Curious, is this really expected or more of a hack for programs which don't ensure cleanup has a well defined order?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious, is this really expected or more of a hack for programs which don't ensure cleanup has a well defined order?

This is a real problem in PyTorch. In particular, we do have quite a few long-lived c++ objects. And because C++ cleanup order is not really guaranteed, it is possible for such a long lived c++ object to hold onto a pyobject. We had quite a few deadlocks because of it pytorch/pytorch#73961 and pytorch/pytorch#57488 are example of cleanups we did there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can remove this if you prefer, but given that our Tensor object is potentially one such c++ owned object and it will call this function on destruction. I would prefer to keep it here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep it indefinitely... It has a bit of a code smell to me, but it's localized enough.

It is annoying to test this (and I guess may be indirectly tested soon at least); so plan to make an exception here and merge it once the test suite is done.

Thanks.

@seberg seberg merged commit 28e9227 into numpy:main Nov 2, 2022
@albanD albanD deleted the fix_gil_dlpack_deleter branch November 2, 2022 19:15
@seberg seberg added the 09 - Backport-Candidate PRs tagged should be backported label Nov 22, 2022
@charris
Copy link
Member

charris commented Nov 30, 2022

@seberg I don't plan on releasing a 1.23.6, not least because parts of the release code will break sometime in December when macos 10.15 goes away.

@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants