Recursing for Progress Bar

Ben Finney bignose+hates-spam at
Tue Sep 19 05:11:47 CEST 2006

"half.italian at" <half.italian at> writes:

> Is there a way to get around recursion limits?  Help!
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>       def incrementProgress(self, window, workorder):
>               #...
> 		time.sleep(.1)
> 		self.incrementProgress(window, workorder)

You don't show a complete working example, so it's hard to know the
context of this.

What is the purpose of this function? Why is it performing these last
two lines at all?

Surely this function should be called by an *external* loop of the
actual processing, with no recursion, and no enforced delay.

    import time

    class ProgressBar(object):
        """ Display of progress as a horizontal bar """

        update_frequency = 0.1

        def __init__(self, window):
            self.window = window
            self._prev_increment_time = 0

        def increment(self, workorder):
            """ Increment the progress display """
            # ... code to unconditionally update the display
            self._prev_update_time = time.time()

        def update(self, workorder):
            """ Update the progress if necessary """
            time_since_update = time.time() - self._prev_update_time
            if time_since_update >= self.update_frequency:

    window = however_you_make_a_window()
    bar = ProgressBar(window)

    for foo in iterator_of_foos:
        workorder = do_the_processing(foo)

 \     "Buy not what you want, but what you need; what you do not need |
  `\           is expensive at a penny."  -- Cato, 234-149 BC, Relique |
_o__)                                                                  |
Ben Finney

More information about the Python-list mailing list