Skip to content

Commit acabf69

Browse files
committed
play_file example: make exception handling more idiomatic
1 parent 45169f8 commit acabf69

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

examples/play_file.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@
55
66
"""
77
import argparse
8-
import sounddevice as sd
9-
import soundfile as sf
10-
import sys
118

129
parser = argparse.ArgumentParser(description=__doc__)
1310
parser.add_argument("filename", help="audio file to be played back")
1411
parser.add_argument("-d", "--device", type=int, help="device ID")
1512
args = parser.parse_args()
1613

1714
try:
15+
import sounddevice as sd
16+
import soundfile as sf
1817
data, fs = sf.read(args.filename, dtype='float32')
1918
sd.play(data, fs, device=args.device, blocking=True)
20-
except:
19+
except BaseException as e:
2120
# This avoids printing the traceback, especially if Ctrl-C is used.
22-
sys.exit(sys.exc_info()[1])
21+
raise SystemExit(str(e))

0 commit comments

Comments
 (0)