Merge pull request #943 from fusion-engineering-forks/atexit
Call Py_Finalize at exit using libc::atexit.
This commit is contained in:
commit
435536060b
|
@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|||
|
||||
### Changed
|
||||
- Simplify internals of `#[pyo3(get)]` attribute. (Remove the hidden API `GetPropertyValue`.) [#934](https://github.com/PyO3/pyo3/pull/934)
|
||||
- Call `Py_Finalize` at exit to flush buffers, etc. [#943](https://github.com/PyO3/pyo3/pull/943)
|
||||
|
||||
### Removed
|
||||
- Remove `ManagedPyRef` (unused, and needs specialization) [#930](https://github.com/PyO3/pyo3/pull/930)
|
||||
|
|
16
src/gil.rs
16
src/gil.rs
|
@ -83,7 +83,12 @@ pub fn prepare_freethreaded_python() {
|
|||
|
||||
// PyPy does not support the embedding API
|
||||
#[cfg(not(PyPy))]
|
||||
ffi::Py_InitializeEx(0);
|
||||
{
|
||||
ffi::Py_InitializeEx(0);
|
||||
|
||||
// Make sure Py_Finalize will be called before exiting.
|
||||
libc::atexit(finalize);
|
||||
}
|
||||
|
||||
// > Changed in version 3.7: This function is now called by Py_Initialize(), so you don’t have
|
||||
// > to call it yourself anymore.
|
||||
|
@ -356,6 +361,15 @@ fn decrement_gil_count() {
|
|||
})
|
||||
}
|
||||
|
||||
extern "C" fn finalize() {
|
||||
unsafe {
|
||||
if ffi::Py_IsInitialized() != 0 {
|
||||
ffi::PyGILState_Ensure();
|
||||
ffi::Py_Finalize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::{gil_is_acquired, GILPool, GIL_COUNT, OWNED_OBJECTS, POOL};
|
||||
|
|
Loading…
Reference in New Issue