def get_pool():
"""
Use this method to acquire connection pool.
Example usage:
from coreservices.core.rpc import get_pool
# ...
with get_pool().next() as rpc:
rpc.mailer.send_mail(foo='bar')
"""
create_pool_lock.acquire()
global pool
if not pool:
# Lazy instantiation
if not hasattr(settings, 'NAMEKO_CONFIG') or not settings.NAMEKO_CONFIG:
raise ImproperlyConfigured('NAMEKO_CONFIG must be specified and should include at least "AMQP_URL" key.')
pool = ClusterRpcProxyPool(settings.NAMEKO_CONFIG)
pool.start()
create_pool_lock.release()
return pool
评论列表
文章目录