diff --git a/python/lammps.py b/python/lammps.py
index 0a996d0235608f0dcbb2270590d90f8a81dc61ce..9f7e02e8e456bdadc574576cfdc247b670a05cc5 100644
--- a/python/lammps.py
+++ b/python/lammps.py
@@ -304,6 +304,9 @@ class OutputCapture(object):
 
   def __exit__(self, type, value, tracebac):
     os.dup2(self.stdout, self.stdout_fd)
+    os.close(self.stdout)
+    os.close(self.stdout_pipe_read)
+    os.close(self.stdout_pipe_write)
 
   # check if we have more to read from the pipe
   def more_data(self, pipe):