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

Alternative approach to redirect outputs to tqdm.write() #197

Open
lrq3000 opened this issue Jul 18, 2016 · 2 comments
Open

Alternative approach to redirect outputs to tqdm.write() #197

lrq3000 opened this issue Jul 18, 2016 · 2 comments
Labels
help wanted 🙏 We need you (discussion or implementation)

Comments

@lrq3000
Copy link
Member

lrq3000 commented Jul 18, 2016

A StackOverflow user reported another way to redirect all outputs to tqdm.write(), which is a lot more concise and as effective as ours, even more so in cases where we want to redirect all printings in all channels, not just stdout:

import inspect
import tqdm
# store builtin print
old_print = print
def new_print(*args, **kwargs):
    # if tqdm.tqdm.write raises error, use builtin print
    try:
        tqdm.tqdm.write(*args, **kwargs)
    except:
        old_print(*args, ** kwargs)
# globaly replace print with new_print
inspect.builtins.print = new_print

Maybe we should add it to the documentation?

@lrq3000 lrq3000 added the help wanted 🙏 We need you (discussion or implementation) label Jul 18, 2016
@lrq3000
Copy link
Member Author

lrq3000 commented Aug 11, 2016

Also an example custom handler for logging should be added:

http://stackoverflow.com/a/38739634/1121352

(there is also another issue here IIRC, should dig it up)

@lrq3000
Copy link
Member Author

lrq3000 commented Dec 29, 2016

Another way of redirecting output, when using multiprocessing: http://stackoverflow.com/a/19421432/1121352

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted 🙏 We need you (discussion or implementation)
Projects
None yet
Development

No branches or pull requests

1 participant