From b33baf1c9f7b2d811ef53f48988aa5d8403bd884 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 25 Aug 2013 19:12:56 +0300 Subject: Issue #18817: Fix a resource warning in Lib/aifc.py demo. --- Lib/aifc.py | 42 +++++++++++++++++++++++------------------- Misc/NEWS | 2 ++ 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/Lib/aifc.py b/Lib/aifc.py index 29545a5..3270047 100644 --- a/Lib/aifc.py +++ b/Lib/aifc.py @@ -873,23 +873,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.") diff --git a/Misc/NEWS b/Misc/NEWS index 848332c..6de4812 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -378,6 +378,8 @@ Documentation 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. -- cgit v0.12