summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvuko <vuko@hackerspace.pl>2020-06-11 09:08:18 +0200
committervuko <vuko@hackerspace.pl>2020-06-11 09:08:18 +0200
commitfa542ad1796c9fc42b779da025e1a994a50eee26 (patch)
treee0536b08f5bd46e4b92a3b2834e298753aaa5e65
parent13110667b58710f243c5c37fa921aa60e8ef38a8 (diff)
downloadcheckinator-fa542ad1796c9fc42b779da025e1a994a50eee26.tar.gz
checkinator-fa542ad1796c9fc42b779da025e1a994a50eee26.tar.bz2
checkinator-fa542ad1796c9fc42b779da025e1a994a50eee26.zip
use threading.lock as context_manager
-rw-r--r--at.py18
1 files changed, 8 insertions, 10 deletions
diff --git a/at.py b/at.py
index c50ddd8..0c5fb63 100644
--- a/at.py
+++ b/at.py
@@ -117,10 +117,9 @@ class Updater(threading.Thread):
del self.active[addr]
def get_active_devices(self):
- self.lock.acquire()
- self.purge_stale()
- r = dict(self.active)
- self.lock.release()
+ with self.lock:
+ self.purge_stale()
+ r = dict(self.active)
return r
def get_device(self, ip):
@@ -135,12 +134,11 @@ class Updater(threading.Thread):
atime -= self.lease_offset
else:
atime = time()
- self.lock.acquire()
- if hwaddr not in self.active or self.active[hwaddr][0] < atime:
- self.active[hwaddr] = (atime, ip, name)
- app.logger.info('updated %s with atime %s and ip %s',
- hwaddr, strfts(atime), ip)
- self.lock.release()
+ with self.lock:
+ if hwaddr not in self.active or self.active[hwaddr][0] < atime:
+ self.active[hwaddr] = (atime, ip, name)
+ app.logger.info('updated %s with atime %s and ip %s',
+ hwaddr, strfts(atime), ip)
class CapUpdater(Updater):