All pastes #840080 Raw Edit

val

public python v1 · immutable
#840080 ·published 2007-12-31 13:37 UTC
rendered paste body
    def pop_connection(self, identifier):        self.global_max.acquire()        try:            self.lock.acquire()            if identifier not in self.clists:                self.clists[identifier] = ConnectionList(self.max_connections_per_host)            clist = self.clists[identifier]            self.lock.release()            if not clist.max.acquire(false): # acquire local lock, releasing global lock when waiting                self.global_max.release()                clist.max.acquire()                self.global_max.acquire()            try:                # we hebben nu zowel toestemming voor een global als voor een local connection                # kijk eerst of er zo'n verbinding bestaat                self.lock.acquire()                try:                    if len(clist) > 0:                        connection = clist.pop()                    else:                        # pop the oldest connection from the connection stack                        old_connection = self.connections.pop(0)                        for clist in self.ids:                            if old_connection in clist:                                clist.remove(old_connection)                                break # a connection is in max one clist                        connection = None # signal we need a new connection                finally:                    self.lock.release()            except:                clist.max.release()                            raise        except:            clist.max.release()            raise