From: Luke Kenneth Casson Leighton Date: Fri, 24 Sep 2021 17:09:44 +0000 (+0100) Subject: finally sort out the running-out-of-file-handles X-Git-Tag: sv_maxu_works-initial~833 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0f434e015ecc77c565b04fc9f431c0121ced8945;p=openpower-isa.git finally sort out the running-out-of-file-handles by taking a copy of the object file and placing it into a BytesIO --- 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: