Protecting against callbacks queuing up?

Esben von Buchwald find.mig at paa.google
Wed Aug 26 16:06:01 EDT 2009


Hendrik van Rooyen wrote:
>> would that be usable?
> Probably
>> If so, how?
> 
> This is a guess, for your device,  but I suspect
> something along these lines:
> 
> t = Ao_timer()
> 
> cb = t.after(100,thing_that_does_the_work(with_its_arguments))
> 
> Lots of assumptions here - the 100 should give you a tenth of a second...
> Don't know what the arguments look like, and if you need to pass an instance 
> (like self) - that would depend on where you are calling it from.
> 
> Play and see :-)
> 
> You should also be able to cancel the callback like this:
> 
> t.cancel(cb)
> 
> If you do it before the time out
> 
> - Hendrik
> 

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?

I'm kind of new to all this async python stuff.



More information about the Python-list mailing list