How do I use a progress bar when my script is doing some task that is likely to take time?
For example, a function which takes some time to complete and returns
@Massagran: It works well in my programs. Furthermore, we need to add a counter to indicate the loop times. This counter plays as the argument of the method update
.
For example: read all lines of a test file and treat them on something. Suppose that the function dosth()
do not concern in the variable i
.
lines = open(sys.argv[1]).readlines()
i = 0
widgets=[Percentage(), Bar()]
pbar = ProgressBar(widgets=widgets,maxval=len(lines)).start()
pbar.start()
for line in lines:
dosth();
i += 1
pbar.update(i)
pbar.finish()
The variable i
controls the status of pbar
via the method update