So what should I run at the beginning of my program to make it thread-safe (or thread-aware as I've read in some places):
from gi.repository import Gtk, Gdk, GLib, GObject
import threading
GLib.threads_init() # ?
GObject.threads_init() # YES!
Gdk.threads_init() # ?
my_app()
def my_threaded_func():
Glib.idle_add(lambda: some_gui_action())
Glib.timeout_add(300, lambda: some_gui_action())
t = threading.Thread(target=my_thread_func)
t.daemon = True
t.start()
Gtk.main()
Then, what should I do in my threads? Some kind of lock? Is it safe to use Python's threading library or should I use something in GLib, GObject or Gdk? I know there is a ton of questions/answers/examples out there, but they all contradict each other, are not for Gtk+ 3, or not for Python, or simply incomplete, and even what I considered the official docs for Python GI (http://lazka.github.io/pgi-docs/) does not even mention the existence of GObject.threads_init() and Gdk.threads_init().