示例#1
0
 def __init__(self, *args, **params):
     BasePool.__init__(self, *args, **params)
     self._hosts = {}
     self._lock = RWLock()
示例#2
0
 def __init__(self, *args, **params):
     BasePool.__init__(self, *args, **params)
     self._hosts = {}
     self._lock = RWLock()
示例#3
0
class SimplePool(BasePool):
    
    def __init__(self, *args, **params):
        BasePool.__init__(self, *args, **params)
        self._hosts = {}
        self._lock = RWLock()
        
    def get(self, netloc):
        self._lock.reader_enters()
        try:
            if netloc not in self._hosts:
                return
            host = self._hosts[netloc]     
            conn = host.get()
            return conn
        finally:
            self._lock.reader_leaves()
            
    def put(self, netloc, conn):
        self._lock.writer_enters()
        try:
            if netloc not in self._hosts:
                host = Host(self.keepalive, self.timeout)
                self._hosts[netloc] = host
            else:
                host = self._hosts[netloc] 
            host.put(conn)
        finally:
            self._lock.writer_leaves()
            
    def clear_host(self, netloc):
        self._lock.writer_enters()
        try:
            if netloc not in self._hosts:
                return
            host = self._hosts[netloc]
            host.clear()
        finally:
            self._lock.writer_leaves()
            
    def clear(self):
        self._lock.writer_enters()
        try:
            for netloc, host in self._hosts:
                host.clear()
                del self._hosts[netloc]
        finally:
            self._lock.writer_leaves()
示例#4
0
class SimplePool(BasePool):
    def __init__(self, *args, **params):
        BasePool.__init__(self, *args, **params)
        self._hosts = {}
        self._lock = RWLock()

    def get(self, netloc):
        self._lock.reader_enters()
        try:
            if netloc not in self._hosts:
                return
            host = self._hosts[netloc]
            conn = host.get()
            return conn
        finally:
            self._lock.reader_leaves()

    def put(self, netloc, conn):
        self._lock.writer_enters()
        try:
            if netloc not in self._hosts:
                host = Host(self.keepalive, self.timeout)
                self._hosts[netloc] = host
            else:
                host = self._hosts[netloc]
            host.put(conn)
        finally:
            self._lock.writer_leaves()

    def clear_host(self, netloc):
        self._lock.writer_enters()
        try:
            if netloc not in self._hosts:
                return
            host = self._hosts[netloc]
            host.clear()
        finally:
            self._lock.writer_leaves()

    def clear(self):
        self._lock.writer_enters()
        try:
            for netloc, host in self._hosts:
                host.clear()
                del self._hosts[netloc]
        finally:
            self._lock.writer_leaves()