def get(self, block=True, timeout=None): # The SQLAlchemy Queue class uses a re-entrant mutext by default, # so it's safe to acquire it both here and in the superclass method. with self.mutex: self.cur_backlog += 1 try: if self.max_backlog >= 0: if self.cur_backlog > self.max_backlog: block = False timeout = None return Queue.get(self, block, timeout) finally: self.cur_backlog -= 1
def __init__(self, maxsize=0, max_backlog=-1): self.max_backlog = max_backlog self.cur_backlog = 0 Queue.__init__(self, maxsize)