Reputation:
How do i kill this timer, once it was executed/started ?
def my_timer(*args):
return True# do ur work here, but not for long
gtk.timeout_add(1000, my_timer) # call every min
Upvotes: 0
Views: 270
Reputation:
def my_timer(*args):
return True# do ur work here, but not for long
t =gtk.timeout_add(1000, my_timer) # call every min
time.sleep(5)
gtk.timeout_remove(t) # kill the timer
Upvotes: 0
Reputation: 14607
Two options:
g_source_remove(event_id)
when it's no longer neededAlso, the "call every minute" comment is wrong: the handle will be called every second.
Suggestion: use timeout_add_seconds() if you do not need sub-second accuracy. It allows glib to optimize things and is better for power management.
Upvotes: 1