19.3. Idle Functions

What if you have a function which you want to be called when nothing else is happening ? Use the function:

  source_id = gobject.idle_add(callback, ...)

Any arguments beyond the first (indicated with ...) are passed to the callback in order. The source_id is returned to provide a reference to the handler.

This function causes GTK to call the specified callback function whenever nothing else is happening.

The callback signature is:

  def callback(...):

where the arguments passed to the callback are the same as those specified in the gobject.idle_add() function. As with the other callback functions, returning FALSE will stop the idle callback from being called and returning TRUE causes the callback function to be run at the next idle time.

An idle function can be removed from the queue by calling the function:


with the source_id returned from the gobject.idle_add() function.