From: Lisandro Dalcin Date: Thu, 16 Dec 2010 16:48:38 +0000 (-0300) Subject: fix ResourceWarning about unclosed files in Py 3.2 X-Git-Tag: 0.14.1rc0~13^2~23 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=7a17001df4de919c4b1b56f3b8cc51c6d0a36c16;p=cython.git fix ResourceWarning about unclosed files in Py 3.2 --- diff --git a/Cython/Build/Dependencies.py b/Cython/Build/Dependencies.py index 05c5035f..73b03342 100644 --- a/Cython/Build/Dependencies.py +++ b/Cython/Build/Dependencies.py @@ -220,7 +220,11 @@ def parse_dependencies(source_filename): # Actual parsing is way to slow, so we use regular expressions. # The only catch is that we must strip comments and string # literals ahead of time. - source = Utils.open_source_file(source_filename, "rU").read() + fh = Utils.open_source_file(source_filename, "rU") + try: + source = fh.read() + finally: + fh.close() distutils_info = DistutilsInfo(source) source, literals = strip_string_literals(source) source = source.replace('\\\n', ' ') diff --git a/Cython/Build/Inline.py b/Cython/Build/Inline.py index 622bc61b..2c6db326 100644 --- a/Cython/Build/Inline.py +++ b/Cython/Build/Inline.py @@ -163,7 +163,11 @@ def __invoke(%(params)s): for key, value in literals.items(): module_code = module_code.replace(key, value) pyx_file = os.path.join(lib_dir, module_name + '.pyx') - open(pyx_file, 'w').write(module_code) + fh = open(pyx_file, 'w') + try: + fh.write(module_code) + finally: + fh.close() extension = Extension( name = module_name, sources = [pyx_file],