diff --git a/src/PYTHON/python_impl.cpp b/src/PYTHON/python_impl.cpp index 0c671c0cc7..8c59ef1915 100644 --- a/src/PYTHON/python_impl.cpp +++ b/src/PYTHON/python_impl.cpp @@ -71,23 +71,25 @@ PythonImpl::PythonImpl(LAMMPS *lmp) : Pointers(lmp) PythonImpl::~PythonImpl() { - // clean up - PyGILState_STATE gstate = PyGILState_Ensure(); + if(pyMain) { + // clean up + PyGILState_STATE gstate = PyGILState_Ensure(); - for (int i = 0; i < nfunc; i++) { - delete [] pfuncs[i].name; - deallocate(i); - PyObject *pFunc = (PyObject *) pfuncs[i].pFunc; - Py_XDECREF(pFunc); - } + for (int i = 0; i < nfunc; i++) { + delete [] pfuncs[i].name; + deallocate(i); + PyObject *pFunc = (PyObject *) pfuncs[i].pFunc; + Py_XDECREF(pFunc); + } - // shutdown Python interpreter + // shutdown Python interpreter - if (pyMain && !external_interpreter) { - Py_Finalize(); - } - else { - PyGILState_Release(gstate); + if (!external_interpreter) { + Py_Finalize(); + } + else { + PyGILState_Release(gstate); + } } memory->sfree(pfuncs);