[Sugar-devel] Help Request - Python Timer

James Cameron quozl at laptop.org
Tue Jan 25 21:31:29 EST 2011


G'day Art,

I would not use Timer for that.  Instead, I would call 

gobject.timeout_add(30000, playcsd)

As a result, the playcsd function will be called after 30 seconds, and
if it returns True it will be called in another 30 seconds.  Your
playcsd function currently does not return True, so it would happen
once, 30 seconds in the future.

If there is a possibility you might call gobject.timeout_add again
during these 30 seconds, watch out, because that will mean there will be
two pending events.  You can avoid this by storing the source ID of the
event and clearing it if already set, for instance:

tag = None

...

if tag:
    gobject.source_remove(tag)
tag = gobject.timeout_add(30000, playcsd)

Reference:

http://www.pygtk.org/pygtk2reference/gobject-functions.html#function-gobject--timeout-add

-- 
James Cameron
http://quozl.linux.org.au/


More information about the Sugar-devel mailing list