-
Notifications
You must be signed in to change notification settings - Fork 59
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
Any way to suppress stdout? #40
Comments
Yeah, we need to add a flag to do that (or perhaps, make it quiet by
default and have a verbose flag). Right now there's no way.
It does print those messages to standard error, not standard output, which
is hopefully a little helpful.
I can't remember though -- does the corenlp java system print to stdout?
my guess is there's nothing we can do about that.
…On Wed, Mar 8, 2017 at 12:45 PM, J.J. Miller ***@***.***> wrote:
I was wondering if there was any way to prevent all of the output from the
library when the server is starting up? I know there's ways I can suppress
it myself but I was wondering if there was a way I could do it through the
library.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#40>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAAGjT8XsH0z0o15TeYbOUTjrLxKLOaxks5rjukrgaJpZM4MXF3m>
.
|
After doing some searching I came across this solution. class suppress_stdout_stderr(object):
'''
A context manager for doing a "deep suppression" of stdout and stderr in
Python, i.e. will suppress all print, even if the print originates in a
compiled C/Fortran sub-function.
This will not suppress raised exceptions, since exceptions are printed
to stderr just before a script exits, and after the context manager has
exited (at least, I think that is why it lets exceptions through).
'''
def __init__(self):
# Open a pair of null files
self.null_fds = [os.open(os.devnull,os.O_RDWR) for x in range(2)]
# Save the actual stdout (1) and stderr (2) file descriptors.
self.save_fds = (os.dup(1), os.dup(2))
def __enter__(self):
# Assign the null pointers to stdout and stderr.
os.dup2(self.null_fds[0],1)
os.dup2(self.null_fds[1],2)
def __exit__(self, *_):
# Re-assign the real stdout/stderr back to (1) and (2)
os.dup2(self.save_fds[0],1)
os.dup2(self.save_fds[1],2)
# Close the null files
os.close(self.null_fds[0])
os.close(self.null_fds[1]) Then I just do with suppress_stdout_stderr():
self.process = CoreNLP('ner', corenlp_jars=['/path/to/jars/']) And it works great for me. Thanks for the help! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was wondering if there was any way to prevent all of the output from the library when the server is starting up? I know there's ways I can suppress it myself but I was wondering if there was a way I could do it through the library.
The text was updated successfully, but these errors were encountered: