Esempio n. 1
0
 def test_seconds_to_human(self):
     """ Test seconds_to_human """
     self.assertEqual(utils.seconds_to_human(60), '1m')
     self.assertEqual(utils.seconds_to_human(3600), '1h')
     self.assertEqual(utils.seconds_to_human(86401), '1d 1s')
     self.assertEqual(utils.seconds_to_human(64.2), '1m 4s')
     self.assertEqual(utils.seconds_to_human(64.2, precision=1),
                      '1.0m 4.2s')
Esempio n. 2
0
 def test_seconds_to_human(self):
     """ Test seconds_to_human """
     self.assertEqual(utils.seconds_to_human(60), '1m')
     self.assertEqual(utils.seconds_to_human(3600), '1h')
     self.assertEqual(utils.seconds_to_human(86401), '1d 1s')
     self.assertEqual(utils.seconds_to_human(64.2), '1m 4s')
     self.assertEqual(utils.seconds_to_human(64.2, precision=1),
                      '1.0m 4.2s')
Esempio n. 3
0
    def __sleep(self, remaining: Optional[float] = None, log: bool = True):
        """
        Sleep handles interrupts and changed rate_limit-parameter.

        time.sleep is stopped by signals such as SIGHUP. As rate_limit could
        have been changed, we initialize again and continue to sleep, if
        necessary at all.

        Parameters:
            remaining: Time to sleep. 'rate_limit' parameter by default if None
            log: Log the remaining sleep time, default: True
        """
        starttime = time.time()
        if remaining is None:
            remaining = self.parameters.rate_limit

        while remaining > 0:
            if log:
                self.logger.info("Idling for {:.1f}s ({}) now.".format(remaining,
                                                                       utils.seconds_to_human(remaining)))
            time.sleep(remaining)
            self.__handle_sighup()
            remaining = self.parameters.rate_limit - (time.time() - starttime)
Esempio n. 4
0
    def __sleep(self, remaining: Optional[float] = None, log: bool = True):
        """
        Sleep handles interrupts and changed rate_limit-parameter.

        time.sleep is stopped by signals such as SIGHUP. As rate_limit could
        have been changed, we initialize again and continue to sleep, if
        necessary at all.

        Parameters:
            remaining: Time to sleep. 'rate_limit' parameter by default if None
            log: Log the remaining sleep time, default: True
        """
        starttime = time.time()
        if remaining is None:
            remaining = self.parameters.rate_limit

        while remaining > 0:
            if log:
                self.logger.info("Idling for {:.1f}s ({}) now.".format(remaining,
                                                                       utils.seconds_to_human(remaining)))
            time.sleep(remaining)
            self.__handle_sighup()
            remaining = self.parameters.rate_limit - (time.time() - starttime)