rind: Don't spawn multiple idle sources when tasks are queued

We don't want to overload the application with multiple idle sources
running in parallel.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2019-04-05 10:27:54 -04:00
parent 07d1e1e113
commit 56f7930032
2 changed files with 7 additions and 1 deletions

View File

@ -30,6 +30,7 @@ class EmmentalApplication(Gtk.Application):
Gtk.Application.do_shutdown(self)
if self.idle_id != None:
GLib.source_remove(self.idle_id)
self.idle_id = None
curds.stop()
def do_startup(self):
@ -41,7 +42,8 @@ class EmmentalApplication(Gtk.Application):
return GLib.SOURCE_CONTINUE if self.idle_id else GLib.SOURCE_REMOVE
def task_queued(self):
self.idle_id = GLib.idle_add(self.on_idle)
if self.idle_id == None:
self.idle_id = GLib.idle_add(self.on_idle)
def updown_toggled(self, *args):

View File

@ -24,6 +24,10 @@ class TestGtk(unittest.TestCase):
self.assertIsNone(gtk.Application.idle_id)
gtk.Application.task_queued()
self.assertGreater(gtk.Application.idle_id, 0)
idle_id = gtk.Application.idle_id
gtk.Application.task_queued()
self.assertEqual(gtk.Application.idle_id, idle_id)
gtk.Application.quit()
thread.stop()