summaryrefslogtreecommitdiff
path: root/examples/asyncio_generators.py
diff options
context:
space:
mode:
authorMatthias Geier <Matthias.Geier@gmail.com>2019-09-17 20:12:20 +0200
committerMatthias Geier <Matthias.Geier@gmail.com>2019-09-18 13:10:33 +0200
commita82b9b56d44ed37c587648685826ad56b9177533 (patch)
treebd72d8becf6caaf2079cd4f31db42db4f7cba289 /examples/asyncio_generators.py
parente8253a615d6f70f7a1f6bc662e703a857fd2e8c4 (diff)
DOC: Update examples
Diffstat (limited to 'examples/asyncio_generators.py')
-rwxr-xr-xexamples/asyncio_generators.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/examples/asyncio_generators.py b/examples/asyncio_generators.py
index c1e7bc6..463a650 100755
--- a/examples/asyncio_generators.py
+++ b/examples/asyncio_generators.py
@@ -10,6 +10,7 @@ You need Python 3.7 or newer to run this.
"""
import asyncio
import queue
+import sys
import numpy as np
import sounddevice as sd
@@ -36,7 +37,7 @@ async def stream_generator(blocksize, *, channels=1, dtype='float32',
The output blocks are uninitialized and have to be filled with
appropriate audio signals.
-
+
"""
assert blocksize != 0
q_in = asyncio.Queue()
@@ -97,8 +98,11 @@ async def main(**kwargs):
try:
await audio_task
except asyncio.CancelledError:
- print('wire was cancelled')
+ print('\nwire was cancelled')
if __name__ == "__main__":
- asyncio.run(main(blocksize=1024))
+ try:
+ asyncio.run(main(blocksize=1024))
+ except KeyboardInterrupt:
+ sys.exit('\nInterrupted by user')