finally sort out the running-out-of-file-handles
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 24 Sep 2021 17:09:44 +0000 (18:09 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 24 Sep 2021 17:09:44 +0000 (18:09 +0100)
by taking a copy of the object file and placing it into a BytesIO

src/openpower/simulator/program.py

index a3dd3754c3f2514557a6ffb7b6662fce24397ed4..0adb96812620003a5fe5e1e6640874f1ff822a89 100644 (file)
@@ -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: