summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortdos.apone <toemossgarcia@gmail.com>2017-03-22 10:34:00 -0500
committertdos.apone <toemossgarcia@gmail.com>2017-03-22 10:56:34 -0500
commit1ceba2671c0a572e78170a9049b8d230bdc67685 (patch)
tree79cabb9fd4969b983386609994e8c057db9d9ed4
parentdcf9f7371343c239247ef1f6583559d4f4ff0912 (diff)
fix issue #1; close open streams in exit handler
+ Apparently older versions of portaudio don't handle closing any open streams which would sometimes cause a segmentation fault while exiting python. This commit makes sure any open streams are closed in the atexit handler
-rw-r--r--sounddevice.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/sounddevice.py b/sounddevice.py
index 117962f..4e08fb9 100644
--- a/sounddevice.py
+++ b/sounddevice.py
@@ -2754,6 +2754,15 @@ def _terminate():
def _exit_handler():
assert _initialized >= 0
+
+ # We cleanup any open streams here since older versions of portaudio don't
+ # manage this (see github issue #1)
+ if _last_callback:
+ # NB: calling stop() first is required; without it portaudio hangs when
+ # calling close()
+ _last_callback.stream.stop()
+ _last_callback.stream.close()
+
while _initialized:
_terminate()