2 ms·
Additionaly, def increment(key): with lock(self.lock): value = self.counter_table.get(key) if not value: self.counter
by d0mine 18y ago
Additionaly,
def increment(key):
with lock(self.lock):
value = self.counter_table.get(key)
if not value:
self.counter_table.add(key, 1)
value = 1
Should be replace by:
def increment(self, key):
with lock(self.lock):
value = self.counter_table[key] = self.counter_table.setdefault(key, 0) + 1
return value
UserDict.DictMixin has setdefault method, therefore it is reasonable to assume that a dictionary-like object should have it.