Skip to content

Commit 7ba04e9

Browse files
committed
Try to send PortAudio output to /dev/null
Closes #11.
1 parent 6c31336 commit 7ba04e9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

sounddevice.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2417,6 +2417,28 @@ def _terminate():
24172417
_check(_lib.Pa_Terminate(), "Error terminating PortAudio")
24182418

24192419

2420+
def _ignore_stderr():
2421+
"""Try to forward PortAudio messages from stderr to /dev/null."""
2422+
ffi = _FFI()
2423+
ffi.cdef("""
2424+
/* from stdio.h */
2425+
FILE* fopen(const char* path, const char* mode);
2426+
int fclose(FILE* fp);
2427+
FILE* stderr; /* GNU C library */
2428+
FILE* __stderrp; /* Mac OS X */
2429+
""")
2430+
stdio = ffi.dlopen(None)
2431+
devnull = stdio.fopen(_os.devnull.encode(), b'w')
2432+
try:
2433+
stdio.stderr = devnull
2434+
except KeyError:
2435+
try:
2436+
stdio.__stderrp = devnull
2437+
except KeyError:
2438+
stdio.fclose(devnull)
2439+
2440+
2441+
_ignore_stderr()
24202442
_initialize()
24212443

24222444
if __name__ == '__main__':

0 commit comments

Comments
 (0)