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

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


http://hg.python.org/cpython/rev/e0c33e0c0483
changeset:   85388:e0c33e0c0483
branch:      3.3
parent:      85385:0dbe45697efc
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Sun Aug 25 19:12:56 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
@@ -873,23 +873,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
@@ -378,6 +378,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 Tools/demo/eiffel.py.

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


More information about the Python-checkins mailing list