Skip to content
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

write() not printing #342

Closed
ntomita opened this issue Feb 2, 2017 · 6 comments
Closed

write() not printing #342

ntomita opened this issue Feb 2, 2017 · 6 comments
Labels
p2-bug-warning ⚠ Visual output bad

Comments

@ntomita
Copy link

ntomita commented Feb 2, 2017

While I was investigating a problem in my program where it doesn't show a progress bar, I found another problem so I report it.

I will show up when I use tqdm in REPL, try running following code.

from time import sleep
for i in tqdm(range(10)):
        sleep(1)
        tqdm.write(i)

Sure, it fails since I'm passing an integer. I fix it and run it again,

for i in tqdm(range(10)):
        sleep(1)
        tqdm.write(str(i))

Now it shows just a progress bar, no numbers printed at all.
Empirically speaking It will come back after I do tqdm().clear() and run some extra loops, like in this way...

... 
                                                                                      
                                                                                      
                                                                                      
  0%|                                                          | 0/10 [01:19<?, ?it/s]
3                                                                                     
4                                                                                     
5                                                                                     
6                                                                                     
7                                                                                     
8                                                                                     
9                                                                                     
100%|█████████████████████████████████████████████████| 10/10 [00:10<00:00,  1.00s/it]
>>> 

So, I'm assuming something wrong with buffer handling. Have you ever observed this issue?
I'm using Python3 on mac with newest OS. tqdm have installed via pip3. I use standard terminal for REPL.

@casperdcl
Copy link
Sponsor Member

casperdcl commented Feb 3, 2017

can't reproduce this:

C:\> tqdm --version
4.11.2
C:\> python
Python 2.7.13 |Anaconda 4.2.0 (64-bit)| (default, Dec 19 2016, 13:29:36) [MSC v.
1500 64 bit (AMD64)] on win32
>>> from time import sleep
>>> from tqdm import tqdm, trange
>>> for i in trange(10):
...   sleep(1)
...   tqdm.write(str(i))
...
0
1
2
3
4
5
6
7
8
9
100%|##########################################| 10/10 [00:10<00:00,  1.00s/it]
>>>

What OS and terminal are you using?

@ntomita
Copy link
Author

ntomita commented Feb 3, 2017

Thanks for the reply!

I'm using Python3 on mac with newest OS. tqdm have installed via pip3. I use standard terminal for REPL.

More specifically, I use version 2.7.1 of Terminal app, OS is macOS Sierra ver 10.12.2.
Also, I use Python 3.5.2 with tqdm 4.11.2

You need to fail inside a loop at least once in order to reproduce the behavior. That occurs when you keep using tqdm with second loop after you got some error from first loop, like I did above.

@casperdcl
Copy link
Sponsor Member

ah. ok. so the problem is you write invalid code (writing a non-string). I don't think tqdm (or any other library) should silently work properly in such a case. we could cast all input of tqdm.write to a string but that way lies dragons.

@ntomita
Copy link
Author

ntomita commented Feb 4, 2017

I see. Ya, as you say automatically converting the type of input is obviously a bad idea. Instead, I think the module should be re-initialized when it encounters an exception. I never had such issue when using other modules that's why I reported this issue. I think it is still beneficial to users, but I understand the policy you have.
Anyway, you guys implements an awesome library, many thanks!

@CentralLT
Copy link

@ntomita let's close the issue. I think your question / problem has been resolved.

@casperdcl
Copy link
Sponsor Member

casperdcl commented Aug 9, 2020

I think the module should be re-initialized when it encounters an exception

this might now be the case but I haven't checked. I recall fixing exceptions within iterations but not sure about when calling write().

@casperdcl casperdcl added the p2-bug-warning ⚠ Visual output bad label Aug 9, 2020
@ntomita ntomita closed this as completed Aug 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2-bug-warning ⚠ Visual output bad
Projects
None yet
Development

No branches or pull requests

3 participants