From 20a7a244d78b835473c3e4d9b86e1c991d252daf Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Wed, 15 Aug 2012 01:21:40 -0700 Subject: [PATCH] Make sure to explicitly close opened files. --- django/core/management/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py index 268cd63c38..adf34971f9 100644 --- a/django/core/management/__init__.py +++ b/django/core/management/__init__.py @@ -51,14 +51,19 @@ def find_management_module(app_name): # module, we need look for the case where the project name is part # of the app_name but the project directory itself isn't on the path. try: - f, path, descr = imp.find_module(part,path) + f, path, descr = imp.find_module(part, path) except ImportError as e: if os.path.basename(os.getcwd()) != part: raise e + finally: + if f: + f.close() while parts: part = parts.pop() f, path, descr = imp.find_module(part, path and [path] or None) + if f: + f.close() return path def load_command_class(app_name, name):