fix(core): return None from handle properties during Python shutdown#1754
Merged
Andy-Jost merged 1 commit intoNVIDIA:mainfrom Mar 11, 2026
Merged
fix(core): return None from handle properties during Python shutdown#1754Andy-Jost merged 1 commit intoNVIDIA:mainfrom
Andy-Jost merged 1 commit intoNVIDIA:mainfrom
Conversation
During interpreter finalization, `as_py()` calls `PyImport_ImportModule` which fails because `sys.modules` is being cleared. Guard `make_py()` with `py_is_finalizing()` to return None gracefully instead of raising. Also consolidates the `py_is_finalizing()` helper into the shared header, removing the duplicate definition from resource_handles.cpp. Closes NVIDIA#1748 Made-with: Cursor
Contributor
Author
|
/ok to test 2417006 |
Contributor
This comment has been minimized.
This comment has been minimized.
cpcloud
approved these changes
Mar 11, 2026
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
.handleonStream(or any other cuda.core object) raisesImportErrorbecauseas_py()callsPyImport_ImportModulewhich fails whensys.modulesis being cleared.make_py()withPy_IsFinalizing()(version-gated for Python < 3.13) to returnNonegracefully instead of raising.py_is_finalizing()helper into the shared header, removing the duplicate fromresource_handles.cpp.Changes
resource_handles.hpp: Addpy_is_finalizing()todetailnamespace and guardmake_py()to returnNoneduring finalization.resource_handles.cpp: Remove duplicatepy_is_finalizing()definition, usedetail::py_is_finalizingviausingdeclaration.Test Coverage
Manually verified: a
__del__method accessingStream.handleduring shutdown now receivesNoneinstead of raisingImportError. Automated testing is impractical because__del__timing during shutdown is non-deterministic.Closes #1748
Made with Cursor