From 1220aa2eff0dec432bf6e9e49c01788ecd88f57d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 6 Mar 2021 14:40:18 -0500 Subject: [PATCH] acquire GIL before updating python path --- src/PYTHON/pair_python.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/PYTHON/pair_python.cpp b/src/PYTHON/pair_python.cpp index eb54d1d4e5..b5d6021e1e 100644 --- a/src/PYTHON/pair_python.cpp +++ b/src/PYTHON/pair_python.cpp @@ -49,14 +49,19 @@ PairPython::PairPython(LAMMPS *lmp) : Pair(lmp) { python->init(); // add current directory to PYTHONPATH - PyObject * py_path = PySys_GetObject((char *)"path"); + + PyGILState_STATE gstate = PyGILState_Ensure(); + PyObject *py_path = PySys_GetObject((char *)"path"); PyList_Append(py_path, PY_STRING_FROM_STRING(".")); - // if LAMMPS_POTENTIALS environment variable is set, add it to PYTHONPATH as well - const char * potentials_path = getenv("LAMMPS_POTENTIALS"); + // if LAMMPS_POTENTIALS environment variable is set, + // add it to PYTHONPATH as well + + const char *potentials_path = getenv("LAMMPS_POTENTIALS"); if (potentials_path != nullptr) { PyList_Append(py_path, PY_STRING_FROM_STRING(potentials_path)); } + PyGILState_Release(gstate); } /* ---------------------------------------------------------------------- */