tqdm icon indicating copy to clipboard operation
tqdm copied to clipboard

tqdm.write not working as expected

Open demiangomez opened this issue 6 years ago • 3 comments

Both on Debian and Ubuntu, tqdm.write() is not working as expected.

Messages are written but the progress bar behaves as if I would be using print. This used to work correctly with a previous version of tqdm (4.19.4) but after installing a new server and using version 4.31.1 it now behaves like this:

-- sir.uylp -> no data for requested time window -- sir.uyni -> no data for requested time window -- sir.uypt -> no data for requested time window -- sir.uyri -> no data for requested time window 99%|██████████████████████████████████████▊| 1120/1127 [01:16<00:00, 20.45it/s] -- sir.uyrv -> no data for requested time window -- sir.uysj -> no data for requested time window -- sir.uyta -> no data for requested time window -- sir.valp -> no data for requested time window 100%|██████████████████████████████████████▉| 1124/1127 [01:16<00:00, 22.86it/s] -- sir.varg -> no data for requested time window -- sir.vesl -> adding... -- sir.vico -> no data for requested time window 100%|███████████████████████████████████████| 1127/1127 [01:18<00:00, 14.41it/s]

Note that the text starts at the end of the progress bar. I've searched the issues page but could not find anything similar. Not sure if it is relevant, but I'm running the program over ssh. Again, this work fine with the previous version I had. The code is very simple:

`for Stn in tqdm(sorted(stations), ncols=80):

    NetworkCode = Stn['NetworkCode']
    StationCode = Stn['StationCode']

    rs = cnn.query(
        'SELECT * FROM rinex_proc WHERE "NetworkCode" = \'%s\' AND "StationCode" = \'%s\' AND '
        '"ObservationSTime" >= \'%s\' AND "ObservationETime" <= \'%s\''
        % (NetworkCode, StationCode, (dates[0] - 1).first_epoch(), (dates[1] + 1).last_epoch()))

    if rs.ntuples() > 0:

        tqdm.write(' -- %s.%s -> adding...' % (NetworkCode, StationCode))
        try:
            stn_obj.append(Station(cnn, NetworkCode, StationCode, dates))

        except pyETMException:
            tqdm.write('    %s.%s -> station exists, but there was a problem initializing ETM.'
                       % (NetworkCode, StationCode))
    else:
        tqdm.write(' -- %s.%s -> no data for requested time window' % (NetworkCode, StationCode))`

demiangomez avatar Feb 27 '19 19:02 demiangomez

is this code running in django or similar? And does downgrading just tqdm to 4.19.4 fix it?

casperdcl avatar Mar 04 '19 00:03 casperdcl

No, I'm not using django. I can confirm that after removing version 4.31.1 and installing 4.19.4 the problem is gone.

demiangomez avatar Mar 08 '19 13:03 demiangomez

I can confirm a similar issue with tqdm.write on Ubuntu 18.04 and tqdm==4.31.1 duplicating the progress bar. It appears to be time dependent in python2 and not python3:

simple loop with no sleep

from tqdm import tqdm

for i in tqdm(range(5)):
    tqdm.write('Here: {}'.format(i))

python2.7

  0%|          | 0/5 [00:00<?, ?it/s]Here: 0
Here: 1
Here: 2
Here: 3
Here: 4
100%|██████████| 5/5 [00:00<00:00, 4725.44it/s]

python3.6 :+1:

Here: 0                                               
Here: 1                                               
Here: 2                                               
Here: 3                                               
Here: 4                                               
100%|████████████████| 5/5 [00:00<00:00, 17303.23it/s]

1 sec sleep

import time
from tqdm import tqdm

for i in tqdm(range(5)):
    tqdm.write('Here: {}'.format(i))
    time.sleep(1)

python2.7

  0%|          | 0/5 [00:00<?, ?it/s]Here: 0
 20%|██        | 1/5 [00:01<00:04,  1.00s/it]Here: 1
 40%|████      | 2/5 [00:02<00:03,  1.00s/it]Here: 2
 60%|██████    | 3/5 [00:03<00:02,  1.00s/it]Here: 3
 80%|████████  | 4/5 [00:04<00:01,  1.00s/it]Here: 4
100%|██████████| 5/5 [00:05<00:00,  1.00s/it]

python3.6 :+1:

Here: 0                                               
Here: 1                                               
Here: 2                                               
Here: 3                                               
Here: 4                                               
100%|███████████████████| 5/5 [00:05<00:00,  1.00s/it]

Downgrading to tqdm==4.30.0 fixes this ...

jccurtis avatar Apr 29 '19 23:04 jccurtis