简体   繁体   English

在 Linux “屏幕”命令日志中抑制 tqdm output

[英]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.我有一个脚本,它使用 tqdm 为冗长的处理工作流程制作几个进度条。 Since the process is so lengthy, I use the "screen" command in Linux to run it as a detached process.由于这个过程很长,我使用 Linux 中的“screen”命令将其作为一个分离的进程运行。 I save the output to a log file via a command similar to:我通过类似于以下的命令将 output 保存到日志文件中:

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

Because the output will also contains some reports which are valuable for analysis afterwards.因为 output 还会包含一些报告,对之后的分析很有价值。

The problem is however the output log file from screen is heavily polluted by the many incrementally re-printed loading bars.然而,问题是屏幕上的 output 日志文件被许多增量重新打印的加载条严重污染。 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.所以我不想完全放弃 tqdm。

Is there a way to suppress the tqdm output in the log file after the fact, while still having it displaying "live" when running?有没有办法在事后抑制日志文件中的 tqdm output ,同时在运行时仍然显示“实时”?

It might be due to screen not being UTF-8 characters friendly.这可能是由于screen不是 UTF-8 字符友好。 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.尝试使用 -U 参数调用屏幕: screen -U -r <number>此外,在调用tqdm时,尝试包含参数ascii=True以处理不适合 UTF-8 的屏幕。 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 .对于您的情况,在调用tqdm时使用position参数设置进度条的 position 也是一个好习惯。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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