rsalmei / alive-progress

A new kind of Progress Bar, with real-time throughput, ETA, and very cool animations!
MIT License
5.45k stars 205 forks source link

How to change the refresh rate? #212

Closed 12932 closed 1 year ago

12932 commented 1 year ago

Hi, i'm trying to force the refresh rate of my bar to about 4 times a second

The README mentions that it's possible to calibrate this

an efficient multi-threaded bar, which updates itself at a fraction of the actual processing speed (1,000,000 iterations per second equates to roughly 60 updates per second) to keep CPU usage low and avoid terminal spamming (you can also calibrate this to your liking);

I can see that the bar takes a refresh_secs argument, but since I would like to update every 0.25 seconds, it doesn't like it:

Traceback (most recent call last):
  File "main.py", line 8, in <module>
    with alive_bar(x, refresh_secs=0.25) as bar:
  File "/home/runner/FrigidAmusingTabs/venv/lib/python3.8/site-packages/alive_progress/core/progress.py", line 106, in alive_bar
    config = config_handler(**options)
  File "/home/runner/FrigidAmusingTabs/venv/lib/python3.8/site-packages/alive_progress/core/configuration.py", line 150, in create_context
    local_config = {**global_config, **_parse(theme, options)}
  File "/home/runner/FrigidAmusingTabs/venv/lib/python3.8/site-packages/alive_progress/core/configuration.py", line 174, in _parse
    return {k: validator(k, v) for k, v in options.items()}
  File "/home/runner/FrigidAmusingTabs/venv/lib/python3.8/site-packages/alive_progress/core/configuration.py", line 174, in <dictcomp>
    return {k: validator(k, v) for k, v in options.items()}
  File "/home/runner/FrigidAmusingTabs/venv/lib/python3.8/site-packages/alive_progress/core/configuration.py", line 165, in validator
    raise ValueError(f'invalid config value: {key}={value!r}')
ValueError: invalid config value: refresh_secs=0.25

How can I reduce the refresh rate of my bar, to about 4 times a second?

rsalmei commented 1 year ago

Hi, humm, it is an interesting use, different than what was intended... They are two distinct features: calibrate changes the refresh curve, and refresh_secs makes the refresh fixed. And the latter was made to accommodate long refreshes like hours (currently max 24 hours), I had not thought at all about sub-second refreshes like this... But it is not difficult to implement it. I'll change its internal type to a float instead of an int, and it should work 👍

12932 commented 1 year ago

Thank you Rogério, I have bought you a coffee 😄

rsalmei commented 1 year ago

Awesome, thanks man! You're welcome. It seems to be working, I'll test a bit more and release it with the next major!