From eae3ef05f3ab4f40931356a06f4a4ce598b736ad Mon Sep 17 00:00:00 2001 From: Ryan Lopopolo Date: Mon, 1 Oct 2018 23:53:26 -0700 Subject: [PATCH] Fix ResourceWarning when reading a Python config module (#1889) The raw open call in execfile_() did not close the file handle. --- gunicorn/_compat.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/gunicorn/_compat.py b/gunicorn/_compat.py index 364ec370..2487e7b7 100644 --- a/gunicorn/_compat.py +++ b/gunicorn/_compat.py @@ -60,7 +60,6 @@ def execfile_(fname, *args): if fname.endswith(".pyc"): code = _get_codeobj(fname) else: - code = compile(open(fname, 'rb').read(), fname, 'exec') + with open(fname, 'rb') as file: + code = compile(file.read(), fname, 'exec') return exec(code, *args) - -