Protecting against callbacks queuing up?
ryles
rylesny at gmail.com
Mon Aug 24 22:48:20 EDT 2009
On Aug 23, 8:14 pm, Esben von Buchwald <find.... at paa.google> wrote:
> 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.
>
> What to do? Thanks...
As Dennis pointed out, it sounds like doCallback() is called serially.
That is, you can think of doCallback() as being called in a loop,
rather than entered multiple times simultaneously. Your 'busy' flag is
never actually checked until after it has already been reset to False.
If the data accessed by the callback as a unique copy and has a
timestamp then a simple approach which avoids multithreading would be
to have your callback ensure that any 'old' data is simply ignored.
This will allow it to quickly catch up to a 'new' event.
More information about the Python-list
mailing list