fix ResourceWarning about unclosed files in Py 3.2
authorLisandro Dalcin <dalcinl@gmail.com>
Thu, 16 Dec 2010 16:48:38 +0000 (13:48 -0300)
committerLisandro Dalcin <dalcinl@gmail.com>
Thu, 16 Dec 2010 16:48:38 +0000 (13:48 -0300)
Cython/Build/Dependencies.py
Cython/Build/Inline.py

index 05c5035ff97e6c86872870054548a9898d741dac..73b033422f7c9348eb6195ec5b56433943dc9e6e 100644 (file)
@@ -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', ' ')
index 622bc61b3b11785d76819b368c9edb41791ed7cd..2c6db326ba82f163e298d85f852b0b0f36810787 100644 (file)
@@ -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],