Git Product home page Git Product logo

Comments (2)

mgeier avatar mgeier commented on July 28, 2024

I didn't find a way to redirect the output for all PortAudio calls but still leave stderr working for other uses within Python.

It seems to work by running this before each PortAudio call:

devnull = os.open(os.devnull, os.O_WRONLY)
old_stderr = os.dup(2)
sys.stderr.flush()
os.dup2(devnull, 2)
os.close(devnull)

... and this immediately afterwards (ideally, in a with statement):

os.dup2(old_stderr, 2)
os.close(old_stderr)

However, I'm not sure if I want to add this overhead to every single PortAudio call.

Any comments?

from python-sounddevice.

mgeier avatar mgeier commented on July 28, 2024

I found a different way, but this doesn't work on Windows (and probably Solaris), because there is no symbol named stderr.

On Linux, this works fine:

Add this to the _ffi.cdef() call:

/* from stdio.h */
FILE* fopen(const char* path, const char* mode);
FILE* stderr;

And then add this just before loading the PortAudio library:

# Ignore stderr messages from PortAudio
stdio = _ffi.dlopen(None)
stdio.stderr = stdio.fopen(_os.devnull.encode(), b'w')

This directly overwrites the stderr file stream, which doesn't affect Python's sys.stderr at all.
Therefore, there is no need to undo the redirection in the end.

from python-sounddevice.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.