Set kp_debug, kp_info, kp_warning and kp_error to py::none() when the program terminates. #231
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.
cc @unexploredtest, @axsaucedo, Superchunk. This should fix #230.
Description
The first instance of segfault occurs with a0f9af9, where
// main.cpp - py::object kp_logger; + py::object kp_debug, kp_info, kp_warning, kp_error;
I suspect that the "attributes" of the
Logger
class (in this case,) are cleaned up once when the program terminates and then the static global
py::objects
are cleaned up again, leading to segfault.In PyTorch, there is a similar idea where they use static variables to "cache"
py::object
attributes. Here is a short summary:In this PR from PyTorch, the fix was to set them to
py:none
during cleanup.The pybind docs suggests using the
atexit
for cleanup.It's unclear why this wasn't an issue in
python3.8
and below.Minimal Reproducible Example
git clone https://github.com/pybind/python_example
src/main.cpp
topython3.9 -m pip install .
python3.9 -c "import kp"