from gi.repository import GObject def my_function(): print("Hello, world!") # Schedule a timeout to call my_function() after 5 seconds timeout_id = GObject.timeout_add(5000, my_function) # Wait for the timeout to trigger GObject.MainLoop().run()
from gi.repository import GObject def my_function(): print("Hello, world!") # Schedule a timeout to call my_function() after 10 seconds timeout_id = GObject.timeout_add(10000, my_function) # Wait for 5 seconds, then cancel the timeout GObject.timeout_add(5000, lambda: GObject.source_remove(timeout_id)) # Wait for the timeout to trigger (should never happen, since we cancelled it) GObject.MainLoop().run()In both examples, we import GObject from the gi.repository package library, define a function to be called by the timeout, and schedule the timeout using timeout_add(). Example 1 simply waits for the function to be called, while Example 2 cancels the timeout after a delay. Package/Library: gi.repository