service: don't acquire lock when pool already initialized

pull/607/head
David Wilson 6 years ago
parent f4709b1dc2
commit 50bfe4c746

@ -77,19 +77,24 @@ else:
def get_or_create_pool(size=None, router=None): def get_or_create_pool(size=None, router=None):
global _pool global _pool
global _pool_pid global _pool_pid
_pool_lock.acquire()
try: my_pid = os.getpid()
if _pool_pid != os.getpid(): if _pool is None or my_pid != _pool_pid:
_pool = Pool(router, [], size=size or DEFAULT_POOL_SIZE, # Avoid acquiring heavily contended lock if possible.
overwrite=True) _pool_lock.acquire()
# In case of Broker shutdown crash, Pool can cause 'zombie' try:
# processes. if _pool_pid != my_pid:
mitogen.core.listen(router.broker, 'shutdown', _pool = Pool(router, [], size=size or DEFAULT_POOL_SIZE,
lambda: _pool.stop(join=False)) overwrite=True)
_pool_pid = os.getpid() # In case of Broker shutdown crash, Pool can cause 'zombie'
return _pool # processes.
finally: mitogen.core.listen(router.broker, 'shutdown',
_pool_lock.release() lambda: _pool.stop(join=True))
_pool_pid = os.getpid()
finally:
_pool_lock.release()
return _pool
def call(service_name, method_name, call_context=None, **kwargs): def call(service_name, method_name, call_context=None, **kwargs):

Loading…
Cancel
Save