baseclass: Log if emit() called from non-MainThread

Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
Cole Robinson 2020-01-15 14:38:24 -05:00
parent 5e63e87a8a
commit 9346c22134

View File

@ -171,6 +171,10 @@ class vmmGObject(GObject.GObject):
""" """
GObject emit() wrapper to simplify callers GObject emit() wrapper to simplify callers
""" """
if not self._is_main_thread():
log.error("emitting signal from non-main thread. This is a bug "
"please report it. thread=%s self=%s signal=%s",
self._thread_name(), self, signal_name)
return GObject.GObject.emit(self, signal_name, *args) return GObject.GObject.emit(self, signal_name, *args)
def add_gsettings_handle(self, handle): def add_gsettings_handle(self, handle):
@ -207,6 +211,12 @@ class vmmGObject(GObject.GObject):
t.daemon = True t.daemon = True
t.start() t.start()
def _thread_name(self):
return threading.current_thread().name
def _is_main_thread(self):
return self._thread_name() == "MainThread"
############################## ##############################
# Custom signal/idle helpers # # Custom signal/idle helpers #