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
Using tqdm when redirecting output? #506
Comments
why are you redirecting everything to |
Agreed, maybe this was oversimplified. I usually run scripts on a remote server I connect to via SSH. I use nohup so the script continues running even when I log out.
test.out will in this case be the same as the one I showed. |
I still don't understand what you'd want... you can always python -c 'import tqdm; print([0 for _ in tqdm.trange(int(1e6))][0])' 1>test.out 2>/dev/null |
I'm also a huge fan of tqdm! I was also looking for a solution to this and so far have come up with a work-around. Say you have a module which can be called from an ipython notebook, terminal ipython session, shell command, or called from within a cron job or other batch process where stderr shouldn't just be redirected to null since there are also potential error messages that should be caught. I use the following code down below so that later on I can wrap all long-running iterables in tqdm without having to worry about the context. I borrowed some code from https://stackoverflow.com/questions/47211324/check-if-module-is-running-in-jupyter-or-not and further extended it to check if we are in a terminal session or have our output redirected.
|
OK, I am trying again to explain my issue: I have a script that takes ages to run. I run it on a remote server, and I am connecting to this server over ssh. I am using a tool called nohup, which allows to run this script even after you log out from the ssh-session. (E.g. I can let this script run over the weekend on the server, while my local machine is shut down). Nohup requires that I redirect all input and output. To reproduce the behavior I am talking about, we don't even need nohup: Why do I even care about If I had the option to specify a newline character at the end of the tqdm-output for every iteration, this wouldn't happen. Does it make sense now? @tcrimi I don't see any output of progress when using your solution. |
I think you're trying to say you want to replace
|
Thanks a lot, using cat instead of less/more to read test.err does the trick. |
if just viewing your progress is what you want, you can try running the following command: |
thank you! exactly what I'm looking for!!! |
I use sbatch, which prints into a file. :( |
Saves my day! |
I am having a problem in building a GUI app which uses Stanza. The |
I believe I can answer that: if there's no |
I am sorry to ping on an old issue. I think the solution to cat or tail works great, but there are scenarios where the log may be getting ingested to a central log collection system, and often in those cases the the flushes are triggered on a newline. As a result, the updates are not reported, and the entire thing can be seen only when everything completes. Is there a solution to this? Ideally I would want a solution to work both in interactive mode, when running in a terminal or jupyter notebook, and in "Batch mode" where the script is submitted, and I am monitoring the progress in log file (in which case I am happy to just a log line instead of progress bar meter) |
I am a big fan of tqdm, so thanks for all the good work!
One issue I have is when the output is redirected to a file, the output looks weird. Would it be possible to add an option to have a carriage return at the end of the line for such cases?
E.g. I have a script test.py:
that I run with
python -u test.py &>test.out
then, the output get crumbled:
version: 4.11.2 through conda
OS: Debian 8.10 (jessie)
The text was updated successfully, but these errors were encountered: