From 0f434e015ecc77c565b04fc9f431c0121ced8945 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Fri, 24 Sep 2021 18:09:44 +0100 Subject: [PATCH] finally sort out the running-out-of-file-handles by taking a copy of the object file and placing it into a BytesIO --- src/openpower/simulator/program.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/openpower/simulator/program.py b/src/openpower/simulator/program.py index a3dd3754..0adb9681 100644 --- a/src/openpower/simulator/program.py +++ b/src/openpower/simulator/program.py @@ -62,13 +62,17 @@ class Program: self.close() def _get_binary(self, elffile): - self.binfile = tempfile.NamedTemporaryFile(suffix=".bin") - args = [cmds['objcopy'], - "-O", "binary", - "-I", self.endian_fmt, - elffile.name, - self.binfile.name] - subprocess.check_output(args) + with tempfile.NamedTemporaryFile(suffix=".bin") as binfile: + args = [cmds['objcopy'], + "-O", "binary", + "-I", self.endian_fmt, + elffile.name, + binfile.name] + subprocess.check_output(args) + # copy over to persistent binfile (BytesIO) + self.binfile = BytesIO() + self.binfile.write(binfile.read()) + self.binfile.seek(0) def _link(self, ofile): with tempfile.NamedTemporaryFile(suffix=".elf") as elffile: -- 2.30.2