sleep() function, perhaps.

Skip Montanaro skip at pobox.com
Tue Nov 25 10:00:56 EST 2003


    Ryan> I want to have a row of periods, separated by small, say, .5
    Ryan> second intervals between each other. Thus, for example, making it
    Ryan> have the appearance of a progress "bar".

You might find my progress module at

    http://www.musi-cal.com/~skip/python/progress.py

a good starting point.  Something like

    import progress, time
    ticker = progress.Progress(major=1, minor=1, majormark='.')
    while True:
        ticker.tick()
        time.sleep(0.5)

running in a separate thread should do what you want.

In many situations you want to actually measure progress of some
computation.  If you can wedge in a call to ticker.tick() on each pass of
your main computation loop:

    import progress, time
    ticker = progress.Progress()
    while some_condition_holds:
        one_more_computational_step()
        ticker.tick()

you can watch your computation progress.

This is particularly helpful if you know how many passes you need to make
around the loop:

    import progress, time
    number_of_passes = 10000
    ticker = progress.Progress(title="(%d)" % number_of_passes)
    for i in xrange(number_of_passes):
        one_more_computational_step()
        ticker.tick()

The title displayed tells you how many loops to expect and the dots and
numbers measure your progress:

(10000): .........1.........2.........3.........4

and when you delete the ticker or it goes out-of-scope, it displays the
total number of ticks (which might be lower if the loop was exited
prematurely).

There are more bells and whistles.  Check the Progress class docstring for
full details.

Skip





More information about the Python-list mailing list