Example #1
0
def _get_pools(resource_name: str) -> (ThreadPool, RegisteredResourcePool):

    pool_name = resource_name

    with _pools_lock:

        if pool_name not in _combined_pools:

            # create and cache new thread pool and resource pool for the resource,
            # they are of the same size, so that each thread can always pick a resource

            resource_factory = ResourceFactory(resource_name)

            # note that the hard limit on the resource pool size is greater than the number
            # of worker threads, this way worker threads still have each its guaranteed resource
            # instance whenever necessary, but the sweeper threads also can have their busy slots
            # whenever they intervene for removing the expired connections or warming the pool up

            thread_pool = ThreadPool(resource_name, resource_factory.pool_size)
            resource_pool = RegisteredResourcePool(resource_name, resource_factory,
                                                   resource_factory.pool_size + 2,
                                                   resource_factory.pool_standby,
                                                   resource_factory.pool_cache)

            _combined_pools[pool_name] = (thread_pool, resource_pool)

        return _combined_pools[pool_name]