def clean(self, address): self._lock.acquire() try: host = self.hosts.get(address) if not host: return while host.pool: socket = host.pool.popleft() sock.close(socket) finally: self._lock.release()
def put(self, address, socket): self._lock.acquire() try: host = self.hosts.get(address) if not host: host = _Host(address) if len(host.pool) > self.max_connections: sock.close(socket) return host.pool.append(socket) finally: self._lock.release()