Protecting against callbacks queuing up?

Hendrik van Rooyen hendrik at microcorp.co.za
Thu Aug 27 03:44:06 EDT 2009


On Wednesday 26 August 2009 22:06:01 Esben von Buchwald wrote:

>
> I don't really get it...
>
> I can see that I should put a t.after(...) around the function that does
> the work, when calling it. That delays each call for the given period. I
> just tried it out, the console keeps saying
> -------------------------------------------------------------------------
> Traceback (most recent call last):
>    File "c:\resource\python25\python25.zip\sensorfw.py", line 499, in
> data_cb
>    File "c:\resource\python25\python25.zip\sensorfw.py", line 160, in
> custom_cb
>    File "e:\python\r3s_contextdata.py", line 79, in acc_filter
>      self.acc_callback()
>    File "e:\python\r3s_contextdata.py", line 85, in acc_callback
>      self.doCallback()
>    File "e:\python\r3s_contextdata.py", line 47, in doCallback
>      self.at.after(0.05,self.data_callback)
> RuntimeError: Timer pending - cancel first
>
> -------------------------------------------------------------------------
>
> It seems like i should cancel the current counting timer, when a new
> call comes in - but how to determine when to cancel etc?

Hmm - now I am really starting to fly by the seat of my pants - but it looks 
as if your problem is that your routine is basically being called faster than 
what it can do the processing.

So what I would try is to define a global (you should really acquire a lock, 
but forget that for the moment) So lets call this thing running_calculation.

Then you set this in the routine just before the after call, and reset it just 
before exiting the calculation routine, and if it is set when you get into 
the first routine, then you just exit, without doing the after.   This should 
have the effect of skipping some calls, to make it all manageable.  Then you 
should (hopefully) not have the duplication that it looks to me like you are 
now having.

Bye the way, make the time short - like 1 - it could also be that the time is 
now so long before you start calculating, that you do not have a snowball's 
hope in hell to be finished before the next value comes in.

- Hendrik



More information about the Python-list mailing list