Merge pull request #4296 from radarhere/unlink

Ensure tempfile is unlinked
This commit is contained in:
Hugo van Kemenade 2019-12-25 11:05:20 +02:00 committed by GitHub
commit cd006ce3c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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