Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b33baf1

Browse files
Issue #18817: Fix a resource warning in Lib/aifc.py demo.
1 parent cd0f74b commit b33baf1

2 files changed

Lines changed: 25 additions & 19 deletions

File tree

Lib/aifc.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -873,23 +873,27 @@ def open(f, mode=None):
873873
sys.argv.append('/usr/demos/data/audio/bach.aiff')
874874
fn = sys.argv[1]
875875
f = open(fn, 'r')
876-
print("Reading", fn)
877-
print("nchannels =", f.getnchannels())
878-
print("nframes =", f.getnframes())
879-
print("sampwidth =", f.getsampwidth())
880-
print("framerate =", f.getframerate())
881-
print("comptype =", f.getcomptype())
882-
print("compname =", f.getcompname())
883-
if sys.argv[2:]:
884-
gn = sys.argv[2]
885-
print("Writing", gn)
886-
g = open(gn, 'w')
887-
g.setparams(f.getparams())
888-
while 1:
889-
data = f.readframes(1024)
890-
if not data:
891-
break
892-
g.writeframes(data)
893-
g.close()
876+
try:
877+
print("Reading", fn)
878+
print("nchannels =", f.getnchannels())
879+
print("nframes =", f.getnframes())
880+
print("sampwidth =", f.getsampwidth())
881+
print("framerate =", f.getframerate())
882+
print("comptype =", f.getcomptype())
883+
print("compname =", f.getcompname())
884+
if sys.argv[2:]:
885+
gn = sys.argv[2]
886+
print("Writing", gn)
887+
g = open(gn, 'w')
888+
try:
889+
g.setparams(f.getparams())
890+
while 1:
891+
data = f.readframes(1024)
892+
if not data:
893+
break
894+
g.writeframes(data)
895+
finally:
896+
g.close()
897+
print("Done.")
898+
finally:
894899
f.close()
895-
print("Done.")

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,8 @@ Documentation
378378
Tools/Demos
379379
-----------
380380

381+
- Issue #18817: Fix a resource warning in Lib/aifc.py demo.
382+
381383
- Issue #18439: Make patchcheck work on Windows for ACKS, NEWS.
382384

383385
- Issue #18448: Fix a typo in Tools/demo/eiffel.py.

0 commit comments

Comments
 (0)