From 8a19181847254ab3add8f89541329262d52caa8e Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 10 Apr 2014 20:35:47 +0200 Subject: update status atomically MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/nightshift.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/nightshift.py b/src/nightshift.py index 7a1e36e..6cc4473 100755 --- a/src/nightshift.py +++ b/src/nightshift.py @@ -211,13 +211,15 @@ def read_status(proc): global red_brightnesses, red_temperatures global red_period, red_location global red_status, red_running + released = True while True: got = proc.stdout.readline() if (got is None) or (len(got) == 0): break got = got.decode('utf-8', 'replace')[:-1] (key, value) = got.split(': ') - red_condition.aquire() + if released: + red_condition.aquire() try: if key == 'Location': red_location = [float(v) for v in value.split(', ')] @@ -241,16 +243,19 @@ def read_status(proc): red_brightnesses = [float(v) for v in value.split(':')] else: red_brightness = float(value) - # Neither version is followed by anything, notify - red_condition.notify_all() + # Neither version is followed by anything, notify and release + released = True elif key == 'Status': red_status = value == 'Enabled' - # Not followed by anything, notify + # Not followed by anything, notify and release + released = True + if released: red_condition.notify_all() + red_condition.release() except: pass - red_condition.release() - red_condition.aquire() + if released: + red_condition.aquire() red_running = False red_condition.notify_all() red_condition.release() -- cgit v1.2.3-70-g09d2