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
This commit is contained in:
Jon Dufresne 2019-01-12 18:32:14 -08:00
parent 503138c857
commit 51e95f6252

View File

@ -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