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


doCallback is defined as a callback function for the accelerometer instance, and data_callback does some calculations and show them on the display of the phone.

If it is, in fact, queuing the callbacks then that means that it's just
recording that the callback needs to be called, but doesn't actually do
it while a previous one is in effect, ie it'll wait for the current call
to return before doing the next one.

What to do? Thanks...

If you want to try multithreading you could make the callback just
trigger the actual action in another thread. The other thread could wait
for an event, perform the calculation, then clear any pending events
before waiting again.
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to