calling g_idle_add()
and g_timeout_add()
does not need locking: they are thread safe operations, and guarantee that the callback will be called in the GMainContext
that is currently spinning the main loop.
the documentation you linked says that the callback will need to acquire the GDK master lock; the callback is invoked by GLib, but the lock is provided by GDK, hence you will need to acquire it explicitly to avoid threads interrupting during the callback emission.
for this reason, the C API provides the gdk_threads_add_idle()
and gdk_threads_add_timeout()
functions (and their full() variants), which guarantee to invoke your callback with the GDK lock held. PyGTK does not wrap those functions, because it would need to also hold the Python interpreter lock; this means that you will need to remember to call gdk_threads_enter()
/gdk_threads_leave()
yourself in the callback.