Vimos
Vimos

Reputation: 701

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!

Upvotes: 10

Views: 1936

Answers (2)

Mostafa Jahanifar
Mostafa Jahanifar

Reputation: 71

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

Upvotes: 6

oLen
oLen

Reputation: 5547

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

screen -U

Upvotes: 14

Related Questions