[Python-checkins] cpython (2.7): Issue #18817: Fix a resource warning in Lib/aifc.py demo.

serhiy.storchaka python-checkins at python.org
Sun Aug 25 18:18:26 CEST 2013


http://hg.python.org/cpython/rev/e3eec06aa12e
changeset:   85387:e3eec06aa12e
branch:      2.7
parent:      85384:8eac75276e5b
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Sun Aug 25 19:12:33 2013 +0300
summary:
  Issue #18817: Fix a resource warning in Lib/aifc.py demo.

files:
  Lib/aifc.py |  42 ++++++++++++++++++++++------------------
  Misc/NEWS   |   2 +
  2 files changed, 25 insertions(+), 19 deletions(-)


diff --git a/Lib/aifc.py b/Lib/aifc.py
--- a/Lib/aifc.py
+++ b/Lib/aifc.py
@@ -953,23 +953,27 @@
         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."
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -141,6 +141,8 @@
 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.

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list