diff options
| author | Matthias Geier <Matthias.Geier@gmail.com> | 2022-11-17 20:19:43 +0100 |
|---|---|---|
| committer | Matthias Geier <Matthias.Geier@gmail.com> | 2022-11-17 20:19:43 +0100 |
| commit | 397eac5ac43d1b0335dc1a377cfe1c4a8818cd5e (patch) | |
| tree | 28b844b2dbd478a6bb6ee94854f20ff70d8c21b4 /sounddevice.py | |
| parent | 841e0a1b2ea2367476248e5f0fc6878154949417 (diff) | |
Redirect stderr with os.dup2() instead of CFFI calls
Diffstat (limited to 'sounddevice.py')
| -rw-r--r-- | sounddevice.py | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/sounddevice.py b/sounddevice.py index a0b723b..643d2fe 100644 --- a/sounddevice.py +++ b/sounddevice.py @@ -2823,29 +2823,22 @@ def _initialize(): is automatically called with the ``import sounddevice`` statement. """ - old_stderr = None + devnull = None + old_stderr = 2 # To appease Pyright try: - stdio = _ffi.dlopen(None) + old_stderr = _os.dup(2) + devnull = open(_os.devnull, 'w') + _os.dup2(devnull.fileno(), 2) except OSError: pass - else: - for stderr_name in 'stderr', '__stderrp': - try: - old_stderr = getattr(stdio, stderr_name) - except _ffi.error: - continue - else: - devnull = stdio.fopen(_os.devnull.encode(), b'w') - setattr(stdio, stderr_name, devnull) - break try: _check(_lib.Pa_Initialize(), 'Error initializing PortAudio') global _initialized _initialized += 1 finally: - if old_stderr is not None: - setattr(stdio, stderr_name, old_stderr) - stdio.fclose(devnull) + if devnull is not None: + _os.dup2(old_stderr, 2) + devnull.close() def _terminate(): |
