In my project, I have a Rust struct that will print a log message when it is dropped. In my Python code, this Rust struct lives in global scope and is not deallocated by the interpreter until the Python process exits.
When the Python process exits and drops my Rust struct, pyo3_log::Logger panics when trying to log the message. This is because it tries to acquire the GIL, but since the interpreter is in the process of finalization, the GIL is not available, so pyo3::Python::with_gil panics
Due to PyO3/pyo3#2102, this panic manifests as a SIGABRT being sent to the thread.
--
I think one potential solution is to check that the interpreter is in an initialized state before trying to acquire the GIL using pyo3::ffi::Py_IsInitialized -- however the function is unsafe and I'm not familiar enough with Python internals to know when it is safe to call.
In my project, I have a Rust struct that will print a
logmessage when it is dropped. In my Python code, this Rust struct lives in global scope and is not deallocated by the interpreter until the Python process exits.When the Python process exits and drops my Rust struct,
pyo3_log::Loggerpanics when trying tologthe message. This is because it tries to acquire the GIL, but since the interpreter is in the process of finalization, the GIL is not available, sopyo3::Python::with_gilpanicsDue to PyO3/pyo3#2102, this panic manifests as a SIGABRT being sent to the thread.
--
I think one potential solution is to check that the interpreter is in an initialized state before trying to acquire the GIL using
pyo3::ffi::Py_IsInitialized-- however the function isunsafeand I'm not familiar enough with Python internals to know when it is safe to call.