threadutil: use 'with' statements for lock
Improve code for waiting the accountThreads. Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
parent
29e06a60f9
commit
44a8cf3feb
@ -50,33 +50,24 @@ class accountThreads(object):
|
|||||||
self.list = []
|
self.list = []
|
||||||
|
|
||||||
def add(self, thread):
|
def add(self, thread):
|
||||||
self.lock.acquire()
|
with self.lock:
|
||||||
try:
|
|
||||||
self.list.append(thread)
|
self.list.append(thread)
|
||||||
finally:
|
|
||||||
self.lock.release()
|
|
||||||
|
|
||||||
def remove(self, thread):
|
def remove(self, thread):
|
||||||
self.lock.acquire()
|
with self.lock:
|
||||||
try:
|
|
||||||
self.list.remove(thread)
|
self.list.remove(thread)
|
||||||
finally:
|
|
||||||
self.lock.release()
|
|
||||||
|
|
||||||
def pop(self):
|
def pop(self):
|
||||||
self.lock.acquire()
|
with self.lock:
|
||||||
try:
|
if len(self.list) < 1:
|
||||||
if not len(self.list):
|
|
||||||
return None
|
return None
|
||||||
return self.list.pop()
|
return self.list.pop()
|
||||||
finally:
|
|
||||||
self.lock.release()
|
|
||||||
|
|
||||||
def wait(self):
|
def wait(self):
|
||||||
while 1:
|
while True:
|
||||||
thread = self.pop()
|
thread = self.pop()
|
||||||
if not thread:
|
if thread is None:
|
||||||
return
|
break
|
||||||
thread.join()
|
thread.join()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user