From: Guido van Rossum Date: Tue, 10 Sep 1996 17:37:44 +0000 (+0000) Subject: close module file after loading X-Git-Tag: v1.4~245 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2ea05098eb6e69288b6d78e31115d490b1362ef7;p=thirdparty%2FPython%2Fcpython.git close module file after loading --- diff --git a/Lib/ihooks.py b/Lib/ihooks.py index bdc48e1dfd6e..3a7e4bf020d4 100644 --- a/Lib/ihooks.py +++ b/Lib/ihooks.py @@ -133,16 +133,19 @@ class BasicModuleLoader(_Verbose): def load_module(self, name, stuff): file, filename, (suff, mode, type) = stuff - if type == BUILTIN_MODULE: - return imp.init_builtin(name) - if type == FROZEN_MODULE: - return imp.init_frozen(name) - if type == C_EXTENSION: - return imp.load_dynamic(name, filename, file) - if type == PY_SOURCE: - return imp.load_source(name, filename, file) - if type == PY_COMPILED: - return imp.load_compiled(name, filename, file) + try: + if type == BUILTIN_MODULE: + return imp.init_builtin(name) + if type == FROZEN_MODULE: + return imp.init_frozen(name) + if type == C_EXTENSION: + return imp.load_dynamic(name, filename, file) + if type == PY_SOURCE: + return imp.load_source(name, filename, file) + if type == PY_COMPILED: + return imp.load_compiled(name, filename, file) + finally: + if file: file.close() raise ImportError, "Unrecognized module type (%s) for %s" % \ (`type`, name)