summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sounddevice.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/sounddevice.py b/sounddevice.py
index 3cc09e9..5cdaab9 100644
--- a/sounddevice.py
+++ b/sounddevice.py
@@ -2417,6 +2417,28 @@ def _terminate():
_check(_lib.Pa_Terminate(), "Error terminating PortAudio")
+def _ignore_stderr():
+ """Try to forward PortAudio messages from stderr to /dev/null."""
+ ffi = _FFI()
+ ffi.cdef("""
+ /* from stdio.h */
+ FILE* fopen(const char* path, const char* mode);
+ int fclose(FILE* fp);
+ FILE* stderr; /* GNU C library */
+ FILE* __stderrp; /* Mac OS X */
+ """)
+ stdio = ffi.dlopen(None)
+ devnull = stdio.fopen(_os.devnull.encode(), b'w')
+ try:
+ stdio.stderr = devnull
+ except KeyError:
+ try:
+ stdio.__stderrp = devnull
+ except KeyError:
+ stdio.fclose(devnull)
+
+
+_ignore_stderr()
_initialize()
if __name__ == '__main__':