From bc3925ead55a26b87c19629987636c02e1da6b35 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Mon, 31 Dec 2018 08:27:07 +1100 Subject: [PATCH] Fixed writing to temporary file --- src/PIL/ImageShow.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/PIL/ImageShow.py b/src/PIL/ImageShow.py index 7d758c737..bbd841db7 100644 --- a/src/PIL/ImageShow.py +++ b/src/PIL/ImageShow.py @@ -132,9 +132,9 @@ elif sys.platform == "darwin": def show_file(self, file, **options): """Display given file""" - f, path = tempfile.mkstemp() - f.write(file) - f.close() + fd, path = tempfile.mkstemp() + with os.fdopen(fd, 'w') as f: + f.write(file) with open(path, "r") as f: subprocess.Popen([ 'im=$(cat);' @@ -171,9 +171,9 @@ else: def show_file(self, file, **options): """Display given file""" - f, path = tempfile.mkstemp() - f.write(file) - f.close() + fd, path = tempfile.mkstemp() + with os.fdopen(fd, 'w') as f: + f.write(file) with open(path, "r") as f: command = self.get_command_ex(file, **options)[0] subprocess.Popen([