instancelimitedsems does not need a lock but must be used with global
All the calls to initInstanceLimit are at initialization time from the same thread. Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
parent
c843f34876
commit
f93b0963fa
@ -222,16 +222,16 @@ class ExitNotifyThread(Thread):
|
|||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
instancelimitedsems = {}
|
instancelimitedsems = {}
|
||||||
instancelimitedlock = Lock()
|
|
||||||
|
|
||||||
def initInstanceLimit(instancename, instancemax):
|
def initInstanceLimit(instancename, instancemax):
|
||||||
"""Initialize the instance-limited thread implementation to permit
|
"""Initialize the instance-limited thread implementation to permit
|
||||||
up to intancemax threads with the given instancename."""
|
up to intancemax threads with the given instancename."""
|
||||||
|
|
||||||
instancelimitedlock.acquire()
|
global instancelimitedsems
|
||||||
|
|
||||||
if not instancename in instancelimitedsems:
|
if not instancename in instancelimitedsems:
|
||||||
instancelimitedsems[instancename] = BoundedSemaphore(instancemax)
|
instancelimitedsems[instancename] = BoundedSemaphore(instancemax)
|
||||||
instancelimitedlock.release()
|
|
||||||
|
|
||||||
class InstanceLimitedThread(ExitNotifyThread):
|
class InstanceLimitedThread(ExitNotifyThread):
|
||||||
def __init__(self, instancename, *args, **kwargs):
|
def __init__(self, instancename, *args, **kwargs):
|
||||||
@ -239,10 +239,14 @@ class InstanceLimitedThread(ExitNotifyThread):
|
|||||||
super(InstanceLimitedThread, self).__init__(*args, **kwargs)
|
super(InstanceLimitedThread, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
|
global instancelimitedsems
|
||||||
|
|
||||||
instancelimitedsems[self.instancename].acquire()
|
instancelimitedsems[self.instancename].acquire()
|
||||||
ExitNotifyThread.start(self)
|
ExitNotifyThread.start(self)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
global instancelimitedsems
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ExitNotifyThread.run(self)
|
ExitNotifyThread.run(self)
|
||||||
finally:
|
finally:
|
||||||
|
Loading…
Reference in New Issue
Block a user