Ensure tempfile is unlinked

This commit is contained in:
Andrew Murray 2019-12-25 15:22:54 +11:00
parent 59481f5bb0
commit 1740a1f20e

View File

@ -616,6 +616,7 @@ def _save_netpbm(im, fp, filename):
# below for information on how to enable this.
tempfile = im._dump()
try:
with open(filename, "wb") as f:
if im.mode != "RGB":
subprocess.check_call(
@ -630,7 +631,10 @@ def _save_netpbm(im, fp, filename):
quant_cmd, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL
)
togif_proc = subprocess.Popen(
togif_cmd, stdin=quant_proc.stdout, stdout=f, stderr=subprocess.DEVNULL
togif_cmd,
stdin=quant_proc.stdout,
stdout=f,
stderr=subprocess.DEVNULL,
)
# Allow ppmquant to receive SIGPIPE if ppmtogif exits
@ -643,7 +647,7 @@ def _save_netpbm(im, fp, filename):
retcode = togif_proc.wait()
if retcode:
raise subprocess.CalledProcessError(retcode, togif_cmd)
finally:
try:
os.unlink(tempfile)
except OSError: