When I need a part of my program that has GLib timeout functions set with
self.timeout_id = GLib.timeout_add_seconds(refresh, self._check_price)
I use
def stop(self):
if self.timeout_id:
GLib.source_remove(self.timeout_id)
to make sure this timeout_id
still exists before attempting to remove it.
Yet I still get these pesky error messages from time to time:
Warning: Source ID 443 was not found when attempting to remove it
GLib.source_remove(self.timeout_id)
how do?
The source is obviously getting removed via some other control path than stop()
. The only candidate I can think of here (from the code you’ve provided) is the self._check_price
method. If you’re returning False
/GLib.SOURCE_REMOVE
from that, you should also unset self.timeout_id
:
def _check_price(self):
…
self.timeout_id = 0
return GLib.SOURCE_REMOVE