diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-04-10 20:35:47 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-04-10 20:35:47 +0200 |
commit | 8a19181847254ab3add8f89541329262d52caa8e (patch) | |
tree | 25176de7d5fe11f32505c0d49f17d966b546c657 | |
parent | typo (diff) | |
download | nightshift-8a19181847254ab3add8f89541329262d52caa8e.tar.gz nightshift-8a19181847254ab3add8f89541329262d52caa8e.tar.bz2 nightshift-8a19181847254ab3add8f89541329262d52caa8e.tar.xz |
update status atomically
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rwxr-xr-x | src/nightshift.py | 17 |
1 files 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() |