Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tqdm in screen environment printing new line and unknown charactors

When I use tqdm in screen, it prints a new line indefinitely and unknown characters in the bar.

Epoch 0:   5%|��                           | 255/5474 [03:31<1:12:09,  1.21it/s]
Epoch 0:   2%|�                             | 90/5474 [01:24<1:23:46,  1.07it/s]
Epoch 0:   2%|�                             | 89/5474 [01:23<1:23:57,  1.07it/s]

I used bash as the default shell and added the following configurations

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8

root@35573c9f245c:~/git/pytorch-openai-transformer-lm# cat ~/.screenrc 
# ~/.screenrc
defshell -bash      # dash makes it a login shell

The same code works well in other terminals.

Any hint over this problem? Thanks!

like image 911
Vimos Avatar asked Sep 10 '18 03:09

Vimos


2 Answers

As you guessed, the problem is caused by the unknown characters. Running screen in UTF-8 mode will solve that:

screen -U
like image 171
oLen Avatar answered Nov 15 '22 03:11

oLen


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
like image 37
Mostafa Jahanifar Avatar answered Nov 15 '22 04:11

Mostafa Jahanifar