Skip to content

Commit 89f124b

Browse files
committed
Better file closing?
1 parent bcc7959 commit 89f124b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

sounddevice.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2823,22 +2823,22 @@ def _initialize():
28232823
is automatically called with the ``import sounddevice`` statement.
28242824
28252825
"""
2826-
devnull = None
2827-
old_stderr = 2 # To appease Pyright
2826+
old_stderr = None
28282827
try:
28292828
old_stderr = _os.dup(2)
28302829
devnull = _os.open(_os.devnull, _os.O_WRONLY)
28312830
_os.dup2(devnull, 2)
2831+
_os.close(devnull)
28322832
except OSError:
28332833
pass
28342834
try:
28352835
_check(_lib.Pa_Initialize(), 'Error initializing PortAudio')
28362836
global _initialized
28372837
_initialized += 1
28382838
finally:
2839-
if devnull is not None:
2839+
if old_stderr is not None:
28402840
_os.dup2(old_stderr, 2)
2841-
_os.close(devnull)
2841+
_os.close(old_stderr)
28422842

28432843

28442844
def _terminate():

0 commit comments

Comments
 (0)