-
Notifications
You must be signed in to change notification settings - Fork 301
Avoid race due to deleted imports when cleaning up objects at interpreter shutdown #973
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
Changes from 4 commits
a9165d6
28db9df
33f68da
7155fd1
e0bea0c
b68a5d1
013cf22
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,8 +17,9 @@ from cuda.core.experimental._utils.cuda_utils import ( | |||||||
| CUDAError, | ||||||||
| driver, | ||||||||
| handle_return, | ||||||||
| is_shutting_down | ||||||||
| ) | ||||||||
|
|
||||||||
| import sys | ||||||||
| if TYPE_CHECKING: | ||||||||
| import cuda.bindings | ||||||||
| from cuda.core.experimental._device import Device | ||||||||
|
|
@@ -108,6 +109,14 @@ cdef class Event: | |||||||
| self._ctx_handle = ctx_handle | ||||||||
| return self | ||||||||
|
|
||||||||
| cpdef safe_close(self, is_shutting_down=sys.is_finalizing): | ||||||||
| """Destroy the event.""" | ||||||||
| if self._handle is not None: | ||||||||
| if not is_shutting_down(): | ||||||||
| err, = driver.cuEventDestroy(self._handle) | ||||||||
|
Contributor
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. What's the issue with this?
Suggested change
Then you don't need the global hack.
Member
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. We want to use a field-tested solution (see the internal thread) instead of coming up with a new one.
Contributor
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. How about In this case it also seems particularly suited to the problem being solved here.
Collaborator
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. This is definitely better, but this is still a hack where if we run things under tools like Additionally, we'd need to carry these checks everywhere that code could be called in What if we moved to a
Member
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. As discussed internally,
No, we can't do this (yet), because we currently call Python bindings. Once #866 lands we can switch to this, but I need some time to work it out and I prefer this to be fixed independently (and asap).
Contributor
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. Here are the relevant steps, in order, during interpreter shutdown:
So, it doesn't really matter which approach we take, and it's overall less code and less hacky code to use a standard library builtin.
Contributor
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.
Member
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.
Contributor
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. This makes it sound like the previously proposed solution using atexit would work, but it wouldn't, because It would be more helpful to provide thorough reasoning (as I did above). Right now, it just looks like everything I said was incorrect without any description as to why that is. |
||||||||
| self._handle = None | ||||||||
| raise_if_driver_error(err) | ||||||||
|
|
||||||||
| cpdef close(self): | ||||||||
| """Destroy the event.""" | ||||||||
| if self._handle is not None: | ||||||||
|
|
@@ -116,7 +125,7 @@ cdef class Event: | |||||||
| raise_if_driver_error(err) | ||||||||
|
|
||||||||
| def __del__(self): | ||||||||
| self.close() | ||||||||
| self.safe_close() | ||||||||
|
|
||||||||
| def __isub__(self, other): | ||||||||
| return NotImplemented | ||||||||
|
|
||||||||
Uh oh!
There was an error while loading. Please reload this page.