Add utilities for Python code

This commit is contained in:
Richard Berger 2021-04-06 14:45:07 -04:00
parent 9da49d9c6f
commit e5a665c1d9
No known key found for this signature in database
GPG Key ID: A9E83994E0BA0CAB
1 changed files with 42 additions and 0 deletions

42
src/PYTHON/python_utils.h Normal file
View File

@ -0,0 +1,42 @@
/* -*- c++ -*- ----------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
http://lammps.sandia.gov, Sandia National Laboratories
Steve Plimpton, sjplimp@sandia.gov
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#ifndef LMP_PYTHON_UTILS_H
#define LMP_PYTHON_UTILS_H
#include <Python.h>
namespace LAMMPS_NS {
namespace PyUtils {
class GIL {
PyGILState_STATE gstate;
public:
GIL() : gstate(PyGILState_Ensure()) {
}
~GIL() {
PyGILState_Release(gstate);
}
};
static void Print_Errors() {
PyErr_Print();
PyErr_Clear();
}
}
}
#endif