read into a BytesIO to avoid "too many open files"
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 24 Jul 2020 10:54:24 +0000 (11:54 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 24 Jul 2020 10:54:24 +0000 (11:54 +0100)
 see https://bugs.libre-soc.org/show_bug.cgi?id=438

src/soc/simulator/program.py

index fda0c9594eebc1e1f436bb80157827d6a70bf1a3..d77f9d7839777c3bd607d04cdfc4c617c3dc4268 100644 (file)
@@ -27,7 +27,10 @@ class Program:
             self.obj_fmt = "-le"
 
         if isinstance(instructions, str):  # filename
-            self.binfile = open(instructions, "rb")
+            # read instructions into a BytesIO to avoid "too many open files"
+            with open(instructions, "rb") as f:
+                b = f.read()
+            self.binfile = BytesIO(b, 'rb')
             self.assembly = ''  # noo disassemble number fiiive
             print("program", self.binfile)
         else: