From 89f124b20f994b29a3f37fe21455604d7579cd49 Mon Sep 17 00:00:00 2001 From: Matthias Geier Date: Thu, 17 Nov 2022 20:58:09 +0100 Subject: Better file closing? --- sounddevice.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sounddevice.py b/sounddevice.py index 14653cd..ed72e35 100644 --- a/sounddevice.py +++ b/sounddevice.py @@ -2823,12 +2823,12 @@ def _initialize(): is automatically called with the ``import sounddevice`` statement. """ - devnull = None - old_stderr = 2 # To appease Pyright + old_stderr = None try: old_stderr = _os.dup(2) devnull = _os.open(_os.devnull, _os.O_WRONLY) _os.dup2(devnull, 2) + _os.close(devnull) except OSError: pass try: @@ -2836,9 +2836,9 @@ def _initialize(): global _initialized _initialized += 1 finally: - if devnull is not None: + if old_stderr is not None: _os.dup2(old_stderr, 2) - _os.close(devnull) + _os.close(old_stderr) def _terminate(): -- cgit v1.2.3