diff options
author | vuko <vuko@hackerspace.pl> | 2020-06-11 09:08:18 +0200 |
---|---|---|
committer | vuko <vuko@hackerspace.pl> | 2020-06-11 09:08:18 +0200 |
commit | fa542ad1796c9fc42b779da025e1a994a50eee26 (patch) | |
tree | e0536b08f5bd46e4b92a3b2834e298753aaa5e65 | |
parent | 13110667b58710f243c5c37fa921aa60e8ef38a8 (diff) | |
download | checkinator-fa542ad1796c9fc42b779da025e1a994a50eee26.tar.gz checkinator-fa542ad1796c9fc42b779da025e1a994a50eee26.tar.bz2 checkinator-fa542ad1796c9fc42b779da025e1a994a50eee26.zip |
use threading.lock as context_manager
-rw-r--r-- | at.py | 18 |
1 files changed, 8 insertions, 10 deletions
@@ -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): |