I am currently using OpenCV in Python on the Raspberry Pi 4, and due to a problem with libjpeg I am getting constantly barraged with unnecessary console messages such as this:
Corrupt JPEG data: 10 extraneous bytes before marker 0xd6
My goal is to filter out these messages while still printing any other error messages (and of course normal stdout) in real time. The program is interactive, so I must still be able to provide input to the program while it is running.
I have attempted to disable printing to stderr and stdout (just in case) from within Python using this answer, but it seems that the error is being thrown by a separate process (which I assume is libjpeg) so redirecting sys.stderr from within Python is ineffective. I have also attempted creating a bash one liner to filter out error messages starting with "Corrupt" and ended up with this:
python test.py 2> >(sed -u '/^Corrupt/ d')
This partially works in that it filters out those messages, but it also doesn't display any other error message until the script has ended. So if an error is thrown, it and all other error messages are all displayed at the same time once the script has finished, but only then. And should the process be ended prematurely via CTRL-C, the errors are not shown at all.
Any ideas on how to filter the error stream without buffering all of the other error messages until the end?