Fix NoneType error in deallocator when exiting global scope #19
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.
In the current version, there is a race condition when there are Geometry objects in the global scope as the Python interpreter is exiting. If
torch
gets freed before the Geometry objects, the deallocator will fail becausetorch is None
at that point in the program. This is not a crucial error, since all the work has already been done and the program is exiting, but it's confusing. Here is the error:or alternatively, depending on the stage of the exiting:
Minimal example with PointTransformerV3 from the examples (pytest import in the original example makes torch get freed later, so I re-add the example with only strictly necessary imports)
Running the above python script leads to the NoneType error.
Sanity check, add
to the end of the file, there is no error, as the deallocation is guaranteed to happen before torch is freed.
In the deallocator function, adding the check whether torch is None also fixes this issue, as all memory will be deallocated as the program exits anyway.