From 51e95f62526edd6f06b3e1878a12676ce7e89c77 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Sat, 12 Jan 2019 18:32:14 -0800 Subject: [PATCH] Catch BaseException for resource cleanup handlers In the event of a SystemExit or KeyboardInterrupt, file resources should still be cleaned up before re-raising the exception. https://docs.python.org/3/library/exceptions.html#exception-hierarchy --- src/PIL/Image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 5c1b2a2a7..c6eb26781 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -2663,7 +2663,7 @@ def open(fp, mode="r"): # opening failures that are entirely expected. # logger.debug("", exc_info=True) continue - except Exception: + except BaseException: if exclusive_fp: fp.close() raise