diff options
| author | Matthias Geier <Matthias.Geier@gmail.com> | 2015-11-11 17:34:57 +0100 |
|---|---|---|
| committer | Matthias Geier <Matthias.Geier@gmail.com> | 2015-12-09 11:13:28 +0100 |
| commit | 7ba04e99db273bb32f19e94516fedcb9441125db (patch) | |
| tree | 7144dde1d5913ecf754ce484ac32f80353082c4c | |
| parent | 6c313362da34c8d1dcda28f2e0c9c6ad84912e59 (diff) | |
Try to send PortAudio output to /dev/null
Closes #11.
| -rw-r--r-- | sounddevice.py | 22 |
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__': |
