Fixed assertion "Someone released me too many times: too many tokens!"
This commit is contained in:
@@ -205,13 +205,13 @@ class ProcessPool(object):
|
|||||||
self._pool.release()
|
self._pool.release()
|
||||||
return rv
|
return rv
|
||||||
|
|
||||||
class SharedPool(ProcessPool):
|
class SharedPool(object):
|
||||||
_instance = None
|
_instance = None
|
||||||
def __new__(cls, *args, **kwargs):
|
def __init__(self):
|
||||||
if not cls._instance:
|
if SharedPool._instance is None:
|
||||||
cls._instance = super(SharedPool, cls).__new__(
|
self.__class__._instance = ProcessPool()
|
||||||
cls, *args, **kwargs)
|
def __getattr__(self, key):
|
||||||
return cls._instance
|
return getattr(self._instance, key)
|
||||||
|
|
||||||
def simple_execute(cmd, **kwargs):
|
def simple_execute(cmd, **kwargs):
|
||||||
return SharedPool().simple_execute(cmd, **kwargs)
|
return SharedPool().simple_execute(cmd, **kwargs)
|
||||||
|
@@ -118,5 +118,12 @@ class ProcessTestCase(test.TrialTestCase):
|
|||||||
def test_shared_pool_is_singleton(self):
|
def test_shared_pool_is_singleton(self):
|
||||||
pool1 = process.SharedPool()
|
pool1 = process.SharedPool()
|
||||||
pool2 = process.SharedPool()
|
pool2 = process.SharedPool()
|
||||||
self.assert_(id(pool1) == id(pool2))
|
self.assertEqual(id(pool1._instance), id(pool2._instance))
|
||||||
|
|
||||||
|
def test_shared_pool_works_as_singleton(self):
|
||||||
|
d1 = process.simple_execute('sleep 1')
|
||||||
|
d2 = process.simple_execute('sleep 0.005')
|
||||||
|
# lp609749: would have failed with
|
||||||
|
# exceptions.AssertionError: Someone released me too many times:
|
||||||
|
# too many tokens!
|
||||||
|
return d1
|
||||||
|
Reference in New Issue
Block a user