From 989f2e715610425c904d4a5ad909987a782bbe33 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Wed, 6 Jan 2016 12:06:25 +0100 Subject: port better on_loop scheduling to the gui --- voctogui/lib/connection.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'voctogui') diff --git a/voctogui/lib/connection.py b/voctogui/lib/connection.py index 20197d0..bc8b867 100644 --- a/voctogui/lib/connection.py +++ b/voctogui/lib/connection.py @@ -48,7 +48,6 @@ def enterNonblockingMode(): log.debug('entering nonblocking-mode') conn.setblocking(False) GObject.io_add_watch(conn, GObject.IO_IN, on_data, ['']) - GObject.idle_add(on_loop) def on_data(conn, _, leftovers, *args): global log @@ -80,6 +79,10 @@ def on_data(conn, _, leftovers, *args): log.debug("got line: %r", line) line = line.strip() + if command_queue.empty(): + log.debug('command_queue was empty, re-starting on_loop scheduling') + GObject.idle_add(on_loop) + command_queue.put((line, conn)) if lines[-1] != '': @@ -89,18 +92,23 @@ def on_data(conn, _, leftovers, *args): return True def on_loop(): - global command_queue - '''Command handler. Processes commands in the command queue whenever nothing else is happening (registered as GObject idle callback)''' + + global command_queue + + log.debug('on_loop called') + if command_queue.empty(): - return True + log.debug('command_queue is empty again, stopping on_loop scheduling') + return False line, requestor = command_queue.get() words = line.split() if len(words) < 1: - return True + log.debug('command_queue is empty again, stopping on_loop scheduling') + return False signal = words[0] args = words[1:] -- cgit v1.2.3