from gi.repository import GLib context = GLib.MainContext() # Create new instance
from gi.repository import GLib # Callback function def callback(): print("Hello World") # Create new instance of MainContext context = GLib.MainContext() # Add source with the callback function to the context GLib.timeout_add(1000, callback, context) # Run the context context.iteration(False)
from gi.repository import GLib # Create new instance of MainContext context = GLib.MainContext() # Check if the context is currently active if context.is_owner(): print("Context is active") else: print("Context is not active")In the examples above, we are using the PyGObject library to create and manipulate GLib MainContext objects. The functions and methods used belong to this library.