From ecc9658ccab45d95f3200b1ec0df60a94fbdc7a6 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 10 May 2021 19:19:26 -0400 Subject: [PATCH] Add context manager code to PyLammps --- python/lammps/pylammps.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/python/lammps/pylammps.py b/python/lammps/pylammps.py index be58df373e..dae2efcbe7 100644 --- a/python/lammps/pylammps.py +++ b/python/lammps/pylammps.py @@ -409,6 +409,12 @@ class PyLammps(object): self._enable_cmd_history = False self.runs = [] + def __enter__(self): + return self + + def __exit__(self, ex_type, ex_value, ex_traceback): + self.close() + def __del__(self): if self.lmp: self.lmp.close() self.lmp = None