Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Olu93 opened this issue Oct 20, 2020 · 4 comments
Open

Comments

@Olu93
Copy link

Olu93 commented Oct 20, 2020

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.

@akaszynski
Copy link
Member

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

@magicknight
Copy link

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

@akaszynski
Copy link
Member

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.

@caniko
Copy link

caniko commented Aug 9, 2021

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants