Skip to content

Commit b72bfd0

Browse files
authored
Fix stderr handling for frozen Windows applications
Prevent stderr duplication issues in frozen context on Windows. Fixes #461.
1 parent 715d988 commit b72bfd0

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

src/sounddevice.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2925,13 +2925,17 @@ def _initialize():
29252925
29262926
"""
29272927
old_stderr = None
2928-
try:
2929-
old_stderr = _os.dup(2)
2930-
devnull = _os.open(_os.devnull, _os.O_WRONLY)
2931-
_os.dup2(devnull, 2)
2932-
_os.close(devnull)
2933-
except OSError:
2934-
pass
2928+
# Duping std file descriptors in a frozen context on windows will corrupt
2929+
# the fd and cause issues with e.g. subprocess.check_output. This happens
2930+
# for example in a compiled pyinstaller exe. See #461 for details.
2931+
if _sys.platform != 'win32' or not getattr(_sys, 'frozen', False):
2932+
try:
2933+
old_stderr = _os.dup(2)
2934+
devnull = _os.open(_os.devnull, _os.O_WRONLY)
2935+
_os.dup2(devnull, 2)
2936+
_os.close(devnull)
2937+
except OSError:
2938+
pass
29352939
try:
29362940
_check(_lib.Pa_Initialize(), 'Error initializing PortAudio')
29372941
global _initialized

0 commit comments

Comments
 (0)