简体   繁体   中英

Suppress tqdm output in Linux "screen" command log

I have a script which uses tqdm to make several progress bars for a lengthy processing workflow. Since the process is so lengthy, I use the "screen" command in Linux to run it as a detached process. I save the output to a log file via a command similar to:

screen -dm -L sh -c 'python3 myscript.py'

Because the output will also contains some reports which are valuable for analysis afterwards.

The problem is however the output log file from screen is heavily polluted by the many incrementally re-printed loading bars. But I do like being able to re-attach the process in a terminal so that I can intermittently monitor its progress. So I don't want to ditch tqdm entirely.

Is there a way to suppress the tqdm output in the log file after the fact, while still having it displaying "live" when running?

It might be due to screen not being UTF-8 characters friendly. Try calling screen with -U argument: screen -U -r <number> Also, when calling tqdm , try to include argument ascii=True in order to deal with screen not being UTF-8 friendly. Something like below:

for item in tqdm(items, total=len(items), ascii=True):
        pass

For your case, it is also a good practice to set the position of progress bar using position argument when calling tqdm .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM