From 3e19afedd26e5776693abe98415bdbfce0459854 Mon Sep 17 00:00:00 2001 From: leyghisbb Date: Sun, 30 Aug 2020 11:50:50 +0200 Subject: [PATCH] added some file close handling for paths2openscad --- extensions/fablabchemnitz_paths2openscad.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/extensions/fablabchemnitz_paths2openscad.py b/extensions/fablabchemnitz_paths2openscad.py index 295e6bbb..402345b4 100644 --- a/extensions/fablabchemnitz_paths2openscad.py +++ b/extensions/fablabchemnitz_paths2openscad.py @@ -1368,7 +1368,9 @@ module chamfer_sphere(rad=chamfer, res=chamfer_fn) **{"SCAD": scad_fname, "NAME": self.basename} ) try: - m = re.match(r"(\d+)\s+(.*)", open(pidfile).read()) + pfile=open(pidfile) + m = re.match(r"(\d+)\s+(.*)", pfile.read()) + pfile.close() oldpid = int(m.group(1)) oldcmd = m.group(2) # print >> sys.stderr, "pid {1} seen in {0}".format(pidfile, oldpid) @@ -1400,7 +1402,10 @@ module chamfer_sphere(rad=chamfer, res=chamfer_fn) except OSError as e: raise OSError("%s failed: errno=%d %s" % (cmd, e.errno, e.strerror)) try: - open(pidfile, "w").write(str(proc.pid) + "\n" + cmd + "\n") + pfile = open(pidfile, "w") + pfile.write(str(proc.pid) + "\n" + cmd + "\n") + pfile.close() + except Exception: pass else: @@ -1454,7 +1459,8 @@ module chamfer_sphere(rad=chamfer, res=chamfer_fn) inkex.errormsg("= " * 24) if len <= 0: # something is wrong. better stop here self.options.stlpost = "false" - + stdout.close() + stderr.close() if self.options.stlpost == "true": cmd = self.options.stlpostcmd.format( **{"STL": self.basename + ".stl", "NAME": self.basename} @@ -1481,5 +1487,7 @@ module chamfer_sphere(rad=chamfer, res=chamfer_fn) if stderr: inkex.errmsg("STDERR: {}".format(stderr)) inkex.errormsg("= " * 24) + stdout.close() + stderr.close() -OpenSCAD().run() \ No newline at end of file +OpenSCAD().run()