added some file close handling for paths2openscad

This commit is contained in:
leyghisbb 2020-08-30 11:50:50 +02:00
parent 423fafd352
commit 3e19afedd2

View File

@ -1368,7 +1368,9 @@ module chamfer_sphere(rad=chamfer, res=chamfer_fn)
**{"SCAD": scad_fname, "NAME": self.basename} **{"SCAD": scad_fname, "NAME": self.basename}
) )
try: 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)) oldpid = int(m.group(1))
oldcmd = m.group(2) oldcmd = m.group(2)
# print >> sys.stderr, "pid {1} seen in {0}".format(pidfile, oldpid) # 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: except OSError as e:
raise OSError("%s failed: errno=%d %s" % (cmd, e.errno, e.strerror)) raise OSError("%s failed: errno=%d %s" % (cmd, e.errno, e.strerror))
try: 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: except Exception:
pass pass
else: else:
@ -1454,7 +1459,8 @@ module chamfer_sphere(rad=chamfer, res=chamfer_fn)
inkex.errormsg("= " * 24) inkex.errormsg("= " * 24)
if len <= 0: # something is wrong. better stop here if len <= 0: # something is wrong. better stop here
self.options.stlpost = "false" self.options.stlpost = "false"
stdout.close()
stderr.close()
if self.options.stlpost == "true": if self.options.stlpost == "true":
cmd = self.options.stlpostcmd.format( cmd = self.options.stlpostcmd.format(
**{"STL": self.basename + ".stl", "NAME": self.basename} **{"STL": self.basename + ".stl", "NAME": self.basename}
@ -1481,5 +1487,7 @@ module chamfer_sphere(rad=chamfer, res=chamfer_fn)
if stderr: if stderr:
inkex.errmsg("STDERR: {}".format(stderr)) inkex.errmsg("STDERR: {}".format(stderr))
inkex.errormsg("= " * 24) inkex.errormsg("= " * 24)
stdout.close()
stderr.close()
OpenSCAD().run() OpenSCAD().run()