Skip to content

Commit 1ceba26

Browse files
committed
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
1 parent dcf9f73 commit 1ceba26

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

sounddevice.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2754,6 +2754,15 @@ def _terminate():
27542754

27552755
def _exit_handler():
27562756
assert _initialized >= 0
2757+
2758+
# We cleanup any open streams here since older versions of portaudio don't
2759+
# manage this (see github issue #1)
2760+
if _last_callback:
2761+
# NB: calling stop() first is required; without it portaudio hangs when
2762+
# calling close()
2763+
_last_callback.stream.stop()
2764+
_last_callback.stream.close()
2765+
27572766
while _initialized:
27582767
_terminate()
27592768

0 commit comments

Comments
 (0)