File tree Expand file tree Collapse file tree 2 files changed +8
-23
lines changed Expand file tree Collapse file tree 2 files changed +8
-23
lines changed Original file line number Diff line number Diff line change @@ -2823,29 +2823,22 @@ def _initialize():
28232823 is automatically called with the ``import sounddevice`` statement.
28242824
28252825 """
2826- old_stderr = None
2826+ devnull = None
2827+ old_stderr = 2 # To appease Pyright
28272828 try :
2828- stdio = _ffi .dlopen (None )
2829+ old_stderr = _os .dup (2 )
2830+ devnull = open (_os .devnull , 'w' )
2831+ _os .dup2 (devnull .fileno (), 2 )
28292832 except OSError :
28302833 pass
2831- else :
2832- for stderr_name in 'stderr' , '__stderrp' :
2833- try :
2834- old_stderr = getattr (stdio , stderr_name )
2835- except _ffi .error :
2836- continue
2837- else :
2838- devnull = stdio .fopen (_os .devnull .encode (), b'w' )
2839- setattr (stdio , stderr_name , devnull )
2840- break
28412834 try :
28422835 _check (_lib .Pa_Initialize (), 'Error initializing PortAudio' )
28432836 global _initialized
28442837 _initialized += 1
28452838 finally :
2846- if old_stderr is not None :
2847- setattr ( stdio , stderr_name , old_stderr )
2848- stdio . fclose ( devnull )
2839+ if devnull is not None :
2840+ _os . dup2 ( old_stderr , 2 )
2841+ devnull . close ( )
28492842
28502843
28512844def _terminate ():
Original file line number Diff line number Diff line change 311311int PaWasapi_IsLoopback( PaDeviceIndex device );
312312""" )
313313
314- ffibuilder .cdef ("""
315- /* from stdio.h */
316- FILE* fopen(const char* path, const char* mode);
317- int fclose(FILE* fp);
318- extern FILE* stderr; /* GNU C library */
319- extern FILE* __stderrp; /* macOS */
320- """ )
321-
322314if __name__ == '__main__' :
323315 ffibuilder .compile (verbose = True )
You can’t perform that action at this time.
0 commit comments