pymeshfix
pymeshfix copied to clipboard
Why is the pymeshfix.repair() function printing stuff with verbose=False?
I tried following code
meshfix = mf.MeshFix(mesh)
meshfix.repair(verbose=False)
repaired = meshfix.mesh
For some reason it still prints the values for 0% and 50% in system out.
There's a bit of C++ code that isn't disabled entirely when passing the non-verbose option to the underlying C++ libraries. At worst, you can force python to suppress stdout and stderr by following the steps outlined in this SO answer . Partially reprinted here for clarity with credit to Andras Deak
from contextlib import contextmanager,redirect_stderr,redirect_stdout
from os import devnull
import pymeshfix as mf
@contextmanager
def suppress_stdout_stderr():
"""A context manager that redirects stdout and stderr to devnull"""
with open(devnull, 'w') as fnull:
with redirect_stderr(fnull) as err, redirect_stdout(fnull) as out:
yield (err, out)
meshfix = mf.MeshFix(mesh)
with suppress_stdout_stderr:
meshfix.repair(verbose=False)
repaired = meshfix.mesh
Hi,
I followed the above step to redirect stderr and stdout to devnull, but .repair() function still prints some numbers on the terminal. I am using ubuntu 20.2
The only way I can get around this is by diving into the C++ and removing the print statements. This package wraps the existing C++ by including the C source and headers in this package and then wrapping it with Cython. I've done a 1:1 copy, so modifying is a bit of an anti-pattern. Do you have any suggestions aside from this? If you have a moment, a PR regarding this would be appreciated. See pymeshfix/cython/*.cpp
.
+1