Rockhopper-Technologies / enlighten

Enlighten Progress Bar for Python Console Apps
https://python-enlighten.readthedocs.io
Mozilla Public License 2.0
416 stars 25 forks source link

Set scroll area when calling Counter() directly #52

Closed ngriffiths13 closed 1 year ago

ngriffiths13 commented 1 year ago

Describe the bug When using enlighten and logging, the progress bar is being interrupted everytime I log.

INFO:__main__:LOG
INFO:__main__:LOG
INFO:__main__:LOG
INFO:__main__:LOG
INFO:__main__:LOG
INFO:__main__:LOG
INFO:__main__:LOG
INFO:__main__:LOG
Backtesting  18%|█████████████████████▊                                                                                                   |  9/50 [00:00<00:01, 81.32 bars/s]INFO:__main__:LOG
INFO:__main__:LOG
INFO:__main__:LOG
INFO:__main__:LOG
INFO:__main__:LOG
INFO:__main__:LOG
INFO:__main__:LOG
INFO:__main__:LOG
INFO:__main__:LOG
Backtesting  36%|███████████████████████████████████████████▌                                                                             | 18/50 [00:00<00:00, 81.41 bars/s]INFO:__main__:LOG

To Reproduce

import logging
import time

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

my_list = list(range(50))
pbar = enlighten.Counter(total=len(my_list), desc="Backtesting",
                                      unit="bars", color="blue")

for l in my_list:
    time.sleep(.01)
    logger.info("LOG")
    pbar.update()

Environment (please complete the following information):

avylove commented 1 year ago

The scroll area isn't set when calling Counter() directly. Maybe it should be?

What you want to do is create a manager first.

manager = enlighten.get_manager()
pbar = manager.counter()
ngriffiths13 commented 1 year ago

Ah okay that did the trick. Setting it automatically might be nice. Or at least making it clear that it doesn't in the documentation. Thanks!

avylove commented 1 year ago

In 1.12.0 calling the Counter class directly will now behave the same as using a manager. References to calling directly have been removed from the documentation and it may be dropped in a future release.