Protecting against callbacks queuing up?

Hendrik van Rooyen hendrik at microcorp.co.za
Mon Aug 24 04:40:06 EDT 2009


On Monday 24 August 2009 02:14:24 Esben von Buchwald wrote:
> Hello
>
> I'm using Python for S60 1.9.7 on my Nokia phone.
>
> I've made a program that gets input from an accelerometer sensor, and
> then calculates some stuff and displays the result.
>
> The sensor framework API does a callback to a function defined by me,
> every time new data is available.
>
> The problem is, that sometimes, the calculations may take longer than
> others, but if the callback is called before the first calculation is
> done, it seems like it's queuing up all the callbacks, and execute them
> sequentially, afterwards.
>
> What I need, is to simply ignore the callback, if the previous call
> hasn't finished it's operations before it's called again.
>
> I thought that this code would do the trick, but it obviously doesn't
> help at all, and i can't understand why...
>
>      def doCallback(self):
>          if self.process_busy==False:
>              self.process_busy=True
>              self.data_callback()
>              self.process_busy=False
>
see if there is an "after" method somewhere.

What you have to do is to "break the link" between the callback
and the processing.  Your code above is all in the callback "thread", despite 
the fact that you call another function to do the processing.

So if you replace the data_callback() with an after call, it should work as 
you expect.

HTH - Hendrik




More information about the Python-list mailing list