mirror of https://github.com/python/cpython
Add try-finally to close the file after loading it in
ModuleLoader.load_module! (Thanks to Daniel Larsson who complained about this.)
This commit is contained in:
parent
6af4abdba0
commit
6dc61b110f
|
@ -252,6 +252,7 @@ class ModuleLoader(BasicModuleLoader):
|
|||
|
||||
def load_module(self, name, stuff):
|
||||
file, filename, (suff, mode, type) = stuff
|
||||
try:
|
||||
if type == BUILTIN_MODULE:
|
||||
return self.hooks.init_builtin(name)
|
||||
if type == FROZEN_MODULE:
|
||||
|
@ -265,6 +266,8 @@ class ModuleLoader(BasicModuleLoader):
|
|||
else:
|
||||
raise ImportError, "Unrecognized module type (%s) for %s" % \
|
||||
(`type`, name)
|
||||
finally:
|
||||
if file: file.close()
|
||||
m.__file__ = filename
|
||||
return m
|
||||
|
||||
|
|
Loading…
Reference in New Issue