[hackers] [wmii] [python] Add some judicious locking. || Kris Maglione

From: <hg_AT_suckless.org>
Date: Sun, 30 May 2010 20:56:42 +0000 (UTC)

changeset: 2679:684dd920d62c
tag: tip
user: Kris Maglione <kris_AT_suckless.org>
date: Sun May 30 16:53:43 2010 -0400
files: alternative_wmiircs/python/pygmi/monitor.py
description:
[python] Add some judicious locking.

diff -r e5503b8254b0 -r 684dd920d62c alternative_wmiircs/python/pygmi/monitor.py
--- a/alternative_wmiircs/python/pygmi/monitor.py Sun May 30 15:29:30 2010 -0400
+++ b/alternative_wmiircs/python/pygmi/monitor.py Sun May 30 16:53:43 2010 -0400
@@ -1,4 +1,4 @@
-from threading import Timer
+from threading import Lock, Timer
 
 from pygmi import client
 from pygmi.fs import *
@@ -69,6 +69,7 @@
         if action:
             self.action = action
 
+ self.lock = Lock()
         self.timer = None
         self.button = Button(self.side, self.name, colors, label)
         self.tick()
@@ -78,21 +79,22 @@
         Called internally at the interval defined by #interval.
         Calls #action and updates the monitor based on the result.
         """
- mon = monitors.get(self.name, None)
- if self.timer and mon is not self:
+ if self.timer and monitors.get(self.name, None) is not self:
             return
         if self.active:
             label = self.getlabel()
             if isinstance(label, basestring):
                 label = None, label
- if label is None:
- self.button.remove()
- else:
- self.button.create(*label)
+ with self.lock:
+ if self.active:
+ if label is None:
+ self.button.remove()
+ else:
+ self.button.create(*label)
 
- self.timer = Timer(self.interval, self.tick)
- self.timer.daemon = True
- self.timer.start()
+ self.timer = Timer(self.interval, self.tick)
+ self.timer.daemon = True
+ self.timer.start()
 
     def getlabel(self):
         """
@@ -106,9 +108,11 @@
 
     _active = True
     def _set_active(self, val):
- self._active = bool(val)
- self.tick()
- if not val:
+ with self.lock:
+ self._active = bool(val)
+ if val:
+ self.tick()
+ else:
             self.button.remove()
 
     active = property(
Received on Sun May 30 2010 - 20:56:42 UTC

This archive was generated by hypermail 2.2.0 : Sun May 30 2010 - 21:00:08 UTC