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