tradingstrategy-ai / tqdm-loggable

Logging friendly progress messages for TQDM progress bars
24 stars 4 forks source link

Extra newline is written when tqdm closes #5

Closed danielnelson closed 11 months ago

danielnelson commented 1 year ago

If I run this script:

import datetime
import logging
import time

from tqdm_loggable.auto import tqdm
from tqdm_loggable.tqdm_logging import tqdm_logging

logging.basicConfig(
    level=logging.INFO
)
tqdm_logging.set_log_rate(datetime.timedelta(seconds=2))

for i in tqdm(range(11)):
    time.sleep(0.5)
for i in tqdm(range(11)):
    time.sleep(0.5)

The actual output is:

INFO:tqdm_loggable.tqdm_logging:Progress on: -/11 rate:- remaining:? elapsed:00:00 postfix:-
INFO:tqdm_loggable.tqdm_logging:Progress on: 4.00it/11.0it rate:2.0it/s remaining:00:03 elapsed:00:02 postfix:-
INFO:tqdm_loggable.tqdm_logging:Progress on: 8.00it/11.0it rate:2.0it/s remaining:00:01 elapsed:00:04 postfix:-
INFO:tqdm_loggable.tqdm_logging:Progress on: 11.0it/11.0it rate:- remaining:? elapsed:00:05 postfix:-

INFO:tqdm_loggable.tqdm_logging:Progress on: -/11 rate:- remaining:? elapsed:00:00 postfix:-
INFO:tqdm_loggable.tqdm_logging:Progress on: 4.00it/11.0it rate:2.0it/s remaining:00:03 elapsed:00:02 postfix:-
INFO:tqdm_loggable.tqdm_logging:Progress on: 8.00it/11.0it rate:2.0it/s remaining:00:01 elapsed:00:04 postfix:-
INFO:tqdm_loggable.tqdm_logging:Progress on: 11.0it/11.0it rate:- remaining:? elapsed:00:05 postfix:-

My expected output is without the extra newline:

INFO:tqdm_loggable.tqdm_logging:Progress on: -/11 rate:- remaining:? elapsed:00:00 postfix:-
INFO:tqdm_loggable.tqdm_logging:Progress on: 4.00it/11.0it rate:2.0it/s remaining:00:03 elapsed:00:02 postfix:-
INFO:tqdm_loggable.tqdm_logging:Progress on: 8.00it/11.0it rate:2.0it/s remaining:00:01 elapsed:00:04 postfix:-
INFO:tqdm_loggable.tqdm_logging:Progress on: 11.0it/11.0it rate:- remaining:? elapsed:00:05 postfix:-
INFO:tqdm_loggable.tqdm_logging:Progress on: -/11 rate:- remaining:? elapsed:00:00 postfix:-
INFO:tqdm_loggable.tqdm_logging:Progress on: 4.00it/11.0it rate:2.0it/s remaining:00:03 elapsed:00:02 postfix:-
INFO:tqdm_loggable.tqdm_logging:Progress on: 8.00it/11.0it rate:2.0it/s remaining:00:01 elapsed:00:04 postfix:-
INFO:tqdm_loggable.tqdm_logging:Progress on: 11.0it/11.0it rate:- remaining:? elapsed:00:05 postfix:-
miohtama commented 11 months ago

Released in 0.2 https://pypi.org/project/tqdm-loggable/