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

Writing the progress to a log file #20

Open
rasbt opened this issue Feb 18, 2016 · 2 comments
Open

Writing the progress to a log file #20

rasbt opened this issue Feb 18, 2016 · 2 comments

Comments

@rasbt
Copy link
Owner

rasbt commented Feb 18, 2016

I think in certain settings, it would be useful to redirect the progress bar/percentage to a log file (for example, if we are running scripts remotely and don't want to maintain a screen session.

An optional argument could be added that accepts a valid file path, e.g.,

ProgBar(..., logfile='path/to/logfile.log') 
ProgPercent(..., logfile='path/to/logfile.log') 
@tommyip
Copy link

tommyip commented Jul 29, 2016

Should the whole progress bar/percentage to be added to the log file as well?
There is also a problem with this, the progress bar doesn't necessary update for every iteration so some item_id may not be included into the log file.

# Test code
def test_logging():
    bar = pyprind.ProgBar(n, logfile='./pyprind.log')
    for i in range(n):
        time.sleep(sleeptime)
        bar.update(item_id=i)

# Log file
[##                            ] | ETA: 00:00:46 | Item ID: 3
[###                           ] | ETA: 00:00:45 | Item ID: 4
[####                          ] | ETA: 00:00:43 | Item ID: 6
[#####                         ] | ETA: 00:00:41 | Item ID: 8
[######                        ] | ETA: 00:00:40 | Item ID: 9
[#######                       ] | ETA: 00:00:38 | Item ID: 11
[########                      ] | ETA: 00:00:36 | Item ID: 13
[#########                     ] | ETA: 00:00:35 | Item ID: 14
[##########                    ] | ETA: 00:00:33 | Item ID: 16
[###########                   ] | ETA: 00:00:31 | Item ID: 18
[############                  ] | ETA: 00:00:30 | Item ID: 19
[#############                 ] | ETA: 00:00:28 | Item ID: 21
[##############                ] | ETA: 00:00:26 | Item ID: 23
[###############               ] | ETA: 00:00:25 | Item ID: 24
[################              ] | ETA: 00:00:23 | Item ID: 26
[#################             ] | ETA: 00:00:21 | Item ID: 28
[##################            ] | ETA: 00:00:20 | Item ID: 29
[###################           ] | ETA: 00:00:18 | Item ID: 31
[####################          ] | ETA: 00:00:16 | Item ID: 33
[#####################         ] | ETA: 00:00:15 | Item ID: 34
[######################        ] | ETA: 00:00:13 | Item ID: 36
[#######################       ] | ETA: 00:00:11 | Item ID: 38
[########################      ] | ETA: 00:00:10 | Item ID: 39
[#########################     ] | ETA: 00:00:08 | Item ID: 41
[##########################    ] | ETA: 00:00:06 | Item ID: 43
[###########################   ] | ETA: 00:00:05 | Item ID: 44
[############################  ] | ETA: 00:00:03 | Item ID: 46
[############################# ] | ETA: 00:00:01 | Item ID: 48
[##############################] | ETA: 00:00:00 | Item ID: 49
[##############################] | ETA: 00:00:00 | Item ID: 49

@rasbt
Copy link
Owner Author

rasbt commented Jul 29, 2016

Should the whole progress bar/percentage to be added to the log file as well?

Hm, I would say yes. It may seem a bit cluttered, but it would be useful to have as much info as possible in logfiles.

There is also a problem with this, the progress bar doesn't necessary update for every iteration so some item_id may not be included into the log file.

I remember that someone mentioned this issue before ... I just see that I added a force_flush parameter at some point. It's at the bottom of the documentation:

http://nbviewer.jupyter.org/github/rasbt/pyprind/blob/master/examples/pyprind_demo.ipynb#Controlling-the-update-frequency

E.g.,

n = 100
bar = pyprind.ProgBar(n, bar_char='█')
for i in range(n):
    time.sleep(0.5) # do some computation
    bar.update(force_flush=True)

Setting force_flush=True would update the bar after each iteration (by default, there's only an update if the progress bar changes; this was done for comp. efficiency).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants