use with subprocess to get it to close Popen files
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 24 Sep 2021 16:55:09 +0000 (17:55 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 24 Sep 2021 16:55:09 +0000 (17:55 +0100)
src/openpower/simulator/program.py

index c2b4adbe1f6acdd1360629e6ac343eb4a9c19881..a3dd3754c3f2514557a6ffb7b6662fce24397ed4 100644 (file)
@@ -88,12 +88,12 @@ class Program:
                     self.obj_fmt,
                     "-o",
                     outfile.name]
-            p = subprocess.Popen(args, stdin=subprocess.PIPE)
-            p.communicate(self.assembly.encode('utf-8'))
-            if p.wait() != 0:
-                print("Error in program:")
-                print(self.assembly)
-                sys.exit(1)
+            with subprocess.Popen(args, stdin=subprocess.PIPE) as p:
+                p.communicate(self.assembly.encode('utf-8'))
+                if p.wait() != 0:
+                    print("Error in program:")
+                    print(self.assembly)
+                    sys.exit(1)
             self._link(outfile)
 
     def _get_instructions(self):