473,322 Members | 1,806 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Recursing for Progress Bar

I'm making a small interface for copying large groups of files around a
filesystem. I have a progressbar that counts the items in the
destination, and increments as each new file is copied over. It
compares this number to the number of files in the source and updates
accordingly.

All is fine and dandy with an average amount of files (<20000), but
when the amount of files to be copied becomes large, I end up getting
"Maximum recurssion depth exceeded" errors. I found out I could find
an safe recursion limit per system, and then set the recursion limit
using sys.setrecursionlimit(), but its still not giving me the depth I
would like. I can also make it work by slowing the update speed way
down, but it just looks clumsy and even then, the top limit could be 10
times the amount of data I'm testing with now...maybe even 200GB. I
don't really know how slow I would need it to update to make sure to
stay below the limit.

Is there a way to get around recursion limits? Help!

~half.italian

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

def incrementProgress(self, window, workorder):
dest_count = workorder.copyIndex
self.label.config(text=workorder.movingFile)
src_count = len(workorder.contents)

if self.p >= 100:
window.destroy()
#
# RESET self.p so future moves work!!
self.p = 0
return

# check for an empty workorder folder...it's already been moved
#
if workorder.contents == []:
window.destroy()
self.p = 0
return
self.p = (float(dest_count)/float(src_count))*100
print "Percentage copied:", self.p

self.progressBar.updateProgress(self.p)

time.sleep(.1)
self.incrementProgress(window, workorder)

Sep 19 '06 #1
3 1317
"ha**********@gmail.com" <ha**********@gmail.comwrites:
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:
self.increment(workorder)

window = however_you_make_a_window()
bar = ProgressBar(window)

for foo in iterator_of_foos:
workorder = do_the_processing(foo)
bar.update(workorder)

--
\ "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

Sep 19 '06 #2
DOLT!

Thanks!

Dennis Lee Bieber wrote:
On 18 Sep 2006 19:38:48 -0700, "ha**********@gmail.com"
<ha**********@gmail.comdeclaimed the following in comp.lang.python:

Is there a way to get around recursion limits? Help!
Yes... restructure your code to not use recursion...

Should be easy since your incomplete snippet implied that there is
NO RETURN VALUE. Recursion is often used when the value of a computation
has to be fed to the next higher level of the calculation (the infamous
factorial:

fact(6) = 6 * fact(6-1)
5 * fact(5-1)
4 * fact(4-1)
3 * fact(3-1)
2 * fact(2-1)
1 (by definition: fact(1) = 1)
2
6
24
120
720

def incrementProgress(self, window, workorder):
while self.p < 100 and workorder.contents:
dest_count = workorder.copyIndex
self.label.config(text=workorder.movingFile)
src_count = len(workorder.contents)
self.p = (float(dest_count) / float(src_count)) * 100.0
print "Percentage copied:", self.p
self.progressBar.updateProgress(self.p)
time.sleep(0.1)

window.destroy()
self.p = 0
return
--
Wulfraed Dennis Lee Bieber KD6MOG
wl*****@ix.netcom.com wu******@bestiaria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: we******@bestiaria.com)
HTTP://www.bestiaria.com/
Sep 19 '06 #3
Makes perfect sense. Sometimes it takes being whacked to see it the
right way.

Thanks!

Ben Finney wrote:
"ha**********@gmail.com" <ha**********@gmail.comwrites:
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:
self.increment(workorder)

window = however_you_make_a_window()
bar = ProgressBar(window)

for foo in iterator_of_foos:
workorder = do_the_processing(foo)
bar.update(workorder)

--
\ "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
Sep 19 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: SpamProof | last post by:
I got an animated gif that is a barber pole spinning that I want to use as a progress bar. The problem is that is stops spinning (shows 1 frame) when my browser is processing a submited request...
7
by: Pepi Tonas | last post by:
I have a form that takes some time to load because it has to populate some Data. I was trying to display a form on top of it with an activity bar so that user can see that something's going on. ...
8
by: WhiteWizard | last post by:
I guess it's my turn to ASK a question ;) Briefly my problem: I am developing a Windows app that has several User Controls. On one of these controls, I am copying/processing some rather large...
1
by: daniel_xi | last post by:
Hi all, I am running a VS 2003 .NET project on my client machine (Win 2000 SP4, ..NET framework 1.1), running an ASP.NET application on a remote web server (Win 2000 Server, IIS 6.0, .NET...
15
by: eladla | last post by:
Hi! I am creating a composite control the does some of it`s own data access. I want to display a progress bar between the time the page is loaded and the control place holder is displayed and...
5
by: Aggelos | last post by:
Hello I am doing sevreral scripts like sending a newsletter that might take a while to finish first to prevent the browser from timing out and to keep the user informed of the process progress I...
0
by: jags_32 | last post by:
Hello We use MFG-PRO as our ERP system which in turn uses Progress databases. In the old version of SQL 2000, using DTS packages, we used to set the code page via command prompts and execute DTS...
9
by: OWeb | last post by:
Javascript and recursing subfolders assistance ------------------------- I have this script that is a free extra download from SlideShowPro. It's a great script but I feel it needs to be...
4
by: Edwin Velez | last post by:
http://msdn.microsoft.com/en-us/library/806sc8c5.aspx The URL above gives sample code for use within a Console Application. What I would like to do is use this code within a Windows Form. That...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.