Skip to content

Commit

Permalink
Close handle returned by tempfile.mkstemp
Browse files Browse the repository at this point in the history
Windows prevents you from deleting a file unless all handles are closed.
This resulted in an exception
  • Loading branch information
justnope committed Sep 10, 2019
1 parent 6f687ae commit 1b3cde6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Render.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,12 +465,13 @@ def render(self,obj,external=True):
template = re.sub("(.*RaytracingContent.*)",cam+"\n"+renderobjs,template)

# save page result
fp = tempfile.mkstemp(prefix=obj.Name,suffix=os.path.splitext(obj.Template)[-1])[1]
fh, fp = tempfile.mkstemp(prefix=obj.Name,suffix=os.path.splitext(obj.Template)[-1])
f = open(fp,"w")
if sys.version_info.major < 3:
template = template.encode("utf8")
f.write(template)
f.close()
os.close(fh)
obj.PageResult = fp
os.remove(fp)

Expand Down
6 changes: 4 additions & 2 deletions renderers/Appleseed.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ def writeObject(viewobj,mesh,color,alpha):

# write the mesh as an obj tempfile

meshfile = tempfile.mkstemp(suffix=".obj", prefix="_")[1]
fd, meshfile = tempfile.mkstemp(suffix=".obj", prefix="_")
os.close(fd)
objfile = os.path.splitext(os.path.basename(meshfile))[0]
mesh.write(meshfile)

Expand Down Expand Up @@ -169,7 +170,8 @@ def render(project,prefix,external,output,width,height):
res = re.findall("<parameter name=\"resolution.*?\/>",t)
if res:
t = t.replace(res[0],"<parameter name=\"resolution\" value=\""+str(width)+" "+str(height)+"\" />")
fp = tempfile.mkstemp(prefix=project.Name,suffix=os.path.splitext(project.Template)[-1])[1]
fd, fp = tempfile.mkstemp(prefix=project.Name,suffix=os.path.splitext(project.Template)[-1])
os.close(fd)
f = open(fp,"w")
f.write(t)
f.close()
Expand Down
3 changes: 2 additions & 1 deletion renderers/Luxrender.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ def render(project,prefix,external,output,width,height):
if res:
t = re.sub("\"integer yresolution\".*?\[.*?\]","\"integer yresolution\" ["+str(height)+"]",t)
if res:
fp = tempfile.mkstemp(prefix=project.Name,suffix=os.path.splitext(project.Template)[-1])[1]
fd, fp = tempfile.mkstemp(prefix=project.Name,suffix=os.path.splitext(project.Template)[-1])
os.close(fd)
f = open(fp,"w")
f.write(t)
f.close()
Expand Down

0 comments on commit 1b3cde6

Please sign in to comment.