pymeshfix icon indicating copy to clipboard operation
pymeshfix copied to clipboard

Why is the pymeshfix.repair() function printing stuff with verbose=False?

Open Olu93 opened this issue 4 years ago • 4 comments

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.

Olu93 avatar Oct 20 '20 15:10 Olu93

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

akaszynski avatar Oct 20 '20 20:10 akaszynski

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

magicknight avatar Feb 24 '21 15:02 magicknight

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.

akaszynski avatar Feb 24 '21 16:02 akaszynski

+1

caniko avatar Aug 09 '21 14:08 caniko