def __init__(self, size, **kwargs): if not isinstance(size, int): raise TypeError("Pool 'size' arg must be an integer") if not size > 0: raise ValueError("Pool 'size' arg must be greater than zero") logger.debug("Initializing connection pool with %d connections", size) self._lock = threading.Lock() self._queue = queue.LifoQueue(maxsize=size) self._thread_connections = threading.local() connection_kwargs = kwargs connection_kwargs['autoconnect'] = False self.connection_kwargs = connection_kwargs for i in range(size): connection = Connection(**connection_kwargs) self._queue.put(connection) # The first connection is made immediately so that trivial # mistakes like unresolvable host names are raised immediately. # Subsequent connections are connected lazily. with self.connection(): pass
def __init__(self): self._mappings = {} self._active = {} self._domains = Node() self._lock = threading.Lock()
def __init__(self, domain=None): self._mappings = defaultdict(set) self._active = defaultdict() self._domains = Node() self._lock = threading.Lock() self._domain = domain.lstrip('.') if domain else None