Open rasbt opened 8 years ago
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
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:
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).
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.,