def test_main(self): cancel = Cancellable() data = [] def func(): data.append(threading.current_thread().name) def callback(result): data.append(threading.current_thread().name) call_async(func, cancel, callback) Gtk.main_iteration() while Gtk.events_pending(): Gtk.main_iteration() call_async_background(func, cancel, callback) Gtk.main_iteration() while Gtk.events_pending(): Gtk.main_iteration() main_name = threading.current_thread().name self.assertEqual(len(data), 4) self.assertNotEqual(data[0], main_name) self.assertEqual(data[1], main_name) self.assertNotEqual(data[2], main_name) self.assertEqual(data[3], main_name)
def plugin_on_changed(self, songs): ratings_dict = { song(ATTR_BRAINZ): int(song(ATTR_RATING) * 100) for song in songs if ATTR_BRAINZ in song and ATTR_RATING in song } if len(ratings_dict): call_async_background( musicbrainzngs.submit_ratings, Cancellable(), callback=lambda *args: (), kwargs=dict(recording_ratings=ratings_dict, ), )