Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/sounddevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -2925,13 +2925,17 @@ def _initialize():

"""
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
# Duping std file descriptors in a frozen context on windows will corrupt
# the fd and cause issues with e.g. subprocess.check_output. This happens
# for example in a compiled pyinstaller exe. See #461 for details.
if _sys.platform != 'win32' or not getattr(_sys, 'frozen', False):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably a matter of taste, but I think this would be easier to understand:

Suggested change
if _sys.platform != 'win32' or not getattr(_sys, 'frozen', False):
if not (_sys.platform == 'win32' and getattr(_sys, 'frozen', False)):

Or maybe you could do something like this:

    if _sys.platform == 'win32' and getattr(_sys, 'frozen', False):
        # the whole comment from above, explaining what's wrong in this case
        pass
    else:
        # the original redirection code

What do you think?

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:
_check(_lib.Pa_Initialize(), 'Error initializing PortAudio')
global _initialized
Expand Down
Loading