]> granicus.if.org Git - python/commitdiff
Issue #18817: Fix a resource warning in Lib/aifc.py demo.
authorSerhiy Storchaka <storchaka@gmail.com>
Sun, 25 Aug 2013 16:12:33 +0000 (19:12 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Sun, 25 Aug 2013 16:12:33 +0000 (19:12 +0300)
Lib/aifc.py
Misc/NEWS

index c2aad1ba66b3ef6e5ba6be91882a57868763a25c..12c665fa8c1ff353afad3f3b93e0d2e1cefb5d61 100644 (file)
@@ -953,23 +953,27 @@ if __name__ == '__main__':
         sys.argv.append('/usr/demos/data/audio/bach.aiff')
     fn = sys.argv[1]
     f = open(fn, 'r')
-    print "Reading", fn
-    print "nchannels =", f.getnchannels()
-    print "nframes   =", f.getnframes()
-    print "sampwidth =", f.getsampwidth()
-    print "framerate =", f.getframerate()
-    print "comptype  =", f.getcomptype()
-    print "compname  =", f.getcompname()
-    if sys.argv[2:]:
-        gn = sys.argv[2]
-        print "Writing", gn
-        g = open(gn, 'w')
-        g.setparams(f.getparams())
-        while 1:
-            data = f.readframes(1024)
-            if not data:
-                break
-            g.writeframes(data)
-        g.close()
+    try:
+        print "Reading", fn
+        print "nchannels =", f.getnchannels()
+        print "nframes   =", f.getnframes()
+        print "sampwidth =", f.getsampwidth()
+        print "framerate =", f.getframerate()
+        print "comptype  =", f.getcomptype()
+        print "compname  =", f.getcompname()
+        if sys.argv[2:]:
+            gn = sys.argv[2]
+            print "Writing", gn
+            g = open(gn, 'w')
+            try:
+                g.setparams(f.getparams())
+                while 1:
+                    data = f.readframes(1024)
+                    if not data:
+                        break
+                    g.writeframes(data)
+            finally:
+                g.close()
+            print "Done."
+    finally:
         f.close()
-        print "Done."
index c295fc39acac79f30b81a597ce327bb619a44299..f7e9372316540aaaee2ff6d7e19648ac6ad67bb3 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -141,6 +141,8 @@ Library
 Tools/Demos
 -----------
 
+- Issue #18817: Fix a resource warning in Lib/aifc.py demo.
+
 - Issue #18439: Make patchcheck work on Windows for ACKS, NEWS.
 
 - Issue #18448: Fix a typo in Demo/newmetaclasses/Eiffel.py.