Merge pull request #450 from rbberger/python_destruction_fix
Prevent segfault if Python was never initialized
This commit is contained in:
@ -45,6 +45,7 @@ Python::Python(LAMMPS *lmp) : Pointers(lmp)
|
|||||||
|
|
||||||
Python::~Python()
|
Python::~Python()
|
||||||
{
|
{
|
||||||
|
if(pyMain) {
|
||||||
// clean up
|
// clean up
|
||||||
PyGILState_STATE gstate = PyGILState_Ensure();
|
PyGILState_STATE gstate = PyGILState_Ensure();
|
||||||
|
|
||||||
@ -57,12 +58,13 @@ Python::~Python()
|
|||||||
|
|
||||||
// shutdown Python interpreter
|
// shutdown Python interpreter
|
||||||
|
|
||||||
if (pyMain && !external_interpreter) {
|
if (!external_interpreter) {
|
||||||
Py_Finalize();
|
Py_Finalize();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
PyGILState_Release(gstate);
|
PyGILState_Release(gstate);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
memory->sfree(pfuncs);
|
memory->sfree(pfuncs);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user