Update code to increment and decrement using the cleaner += 1 and -= 1 style.

This commit is contained in:
Raymond Hettinger 2013-03-10 15:13:35 -07:00
parent fc5c5320a0
commit 720da57159

View file

@ -79,7 +79,7 @@ class _RLock:
def acquire(self, blocking=True, timeout=-1): def acquire(self, blocking=True, timeout=-1):
me = get_ident() me = get_ident()
if self._owner == me: if self._owner == me:
self._count = self._count + 1 self._count += 1
return 1 return 1
rc = self._block.acquire(blocking, timeout) rc = self._block.acquire(blocking, timeout)
if rc: if rc:
@ -261,7 +261,7 @@ class Semaphore:
break break
self._cond.wait(timeout) self._cond.wait(timeout)
else: else:
self._value = self._value - 1 self._value -= 1
rc = True rc = True
self._cond.release() self._cond.release()
return rc return rc
@ -270,7 +270,7 @@ class Semaphore:
def release(self): def release(self):
self._cond.acquire() self._cond.acquire()
self._value = self._value + 1 self._value += 1
self._cond.notify() self._cond.notify()
self._cond.release() self._cond.release()
@ -506,7 +506,7 @@ class BrokenBarrierError(RuntimeError): pass
_counter = 0 _counter = 0
def _newname(template="Thread-%d"): def _newname(template="Thread-%d"):
global _counter global _counter
_counter = _counter + 1 _counter += 1
return template % _counter return template % _counter
# Active thread administration # Active thread administration