Skip to content

GLib.MainLoop

record (struct)

The GMainLoop struct is an opaque data type representing the main event loop of a GLib or GTK application.

Constructors

new

@classmethod
def new(cls, context: MainContext | None, is_running: bool) -> MainLoop

Creates a new MainLoop structure.

Parameters:

  • context — a main context (if NULL, the global-default main context will be used).
  • is_running — set to true to indicate that the loop is running. This is not very important since calling MainLoop.run will set this to true anyway.

Methods

get_context

def get_context(self) -> MainContext

Returns the MainContext of loop.

is_running

def is_running(self) -> bool

Checks to see if the main loop is currently being run via MainLoop.run.

quit

def quit(self) -> None

Stops a MainLoop from running. Any calls to MainLoop.run for the loop will return.

Note that sources that have already been dispatched when MainLoop.quit is called will still be executed.

ref

def ref(self) -> MainLoop

Increases the reference count on a MainLoop object by one.

run

def run(self) -> None

Runs a main loop until MainLoop.quit is called on the loop.

If this is called from the thread of the loop’s MainContext, it will process events from the loop, otherwise it will simply wait.

unref

def unref(self) -> None

Decreases the reference count on a MainLoop object by one.

If the result is zero, the loop and all associated memory are freed.