示例#1
0
    def wait_until_load_low(
        self,
        thresholds: dict[str, int | float] | None = None,
        timeout: float = 60.0,
        sleep: float = 0.1,
    ) -> None:
        if thresholds is None:
            thresholds = {"Threads_running": 10}

        start = time.time()
        names = thresholds.keys()

        while True:
            current = self.get_many(names)
            higher = []
            for name, value in current.items():
                assert isinstance(value, (int, float))
                if value > thresholds[name]:
                    higher.append(name)

            if not higher:
                return

            if timeout and time.time() > start + timeout:
                raise TimeoutError("Span too long waiting for load to drop: " +
                                   ",".join(f"{name} > {thresholds[name]}"
                                            for name in higher))
            time.sleep(sleep)
示例#2
0
 def acquire(self):
     with self.get_cursor() as cursor:
         cursor.execute("SELECT GET_LOCK(%s, %s)",
                        (self.name, self.acquire_timeout))
         result = cursor.fetchone()[0]
         if result == 1:
             return self
         else:
             raise TimeoutError("Waited >{} seconds to gain lock".format(
                 self.acquire_timeout))
示例#3
0
    def wait_until_load_low(self, thresholds=None, timeout=60.0, sleep=0.1):
        if thresholds is None:
            thresholds = {"Threads_running": 10}

        start = time.time()
        names = thresholds.keys()

        while True:
            current = self.get_many(names)

            higher = [
                name for name in names if current[name] > thresholds[name]
            ]
            if not higher:
                return

            if timeout and time.time() > start + timeout:
                raise TimeoutError("Span too long waiting for load to drop: " +
                                   ",".join(f"{name} > {thresholds[name]}"
                                            for name in higher))
            time.sleep(sleep)
示例#4
0
文件: status.py 项目: chiefexb/dbapi
    def wait_until_load_low(self, thresholds=None, timeout=60.0, sleep=0.1):
        if thresholds is None:
            thresholds = {'Threads_running': 5}

        start = time.time()
        names = thresholds.keys()

        while True:
            current = self.get_many(names)

            higher = []
            for name in names:
                if current[name] > thresholds[name]:
                    higher.append(name)

            if not higher:
                return

            if timeout and time.time() > start + timeout:
                raise TimeoutError(
                    "Span too long waiting for load to drop: " +
                    ",".join("{} > {}".format(name, thresholds[name])
                             for name in higher), )
            time.sleep(sleep)