Search code examples
pythonsubprocessmbrola

Subprocess, stderr to DEVNULL but errors are printed


I am working on a French chatbot using python. For a first text-to-speech attempt, I am using espeak with mbrola. I call it with subprocess :

from subprocess import run, DEVNULL

def speak(text):
    command = ["espeak", "-vmb-fr1", text]
    run(command, stderr=DEVNULL, stdout=DEVNULL)

speak("Bonjour.")

As you see, I'm sending stderr and stdout to /dev/null

When I run the program, It seems to work, espeak is speaking, but I get this :

*** Error in `mbrola': free(): invalid pointer: 0x08e3af18 ***
*** Error in `mbrola': free(): invalid pointer: 0x0988af88 ***

I think it is a C error in mbrola. I think I can't fix it. But it works, so I just want to mute the error. How can I do ? Is there a way ?


Edit, in response to abarnert :

When I redirect stdout and stderr by the shell (python myscript.py 2>&1 >/dev/null), the message still show up.

  • distro : Debian 9.3
  • glibc version : 2.24

Solution

  • Run it with setsid (just add that string in front of the command and arguments). That will stop it from opening /dev/tty to report the malloc errors. It will also prevent terminal signals, including SIGHUP when the terminal is closed, from affecting the process, which may be a good or a bad thing.

    Alternatively, set the environment variable LIBC_FATAL_STDERR_ to some nonempty string, with whose name I was able to find several similar questions.