Example #1
0
    def test_check(self):
        with mocks.Time, OutputCapture() as capturer:
            with Timeout(1):
                Timeout.check()
                self.assertRaises(Timeout.Exception, time.sleep, 1)

        self.assertEqual(
            capturer.webkitcorepy.log.getvalue(),
            'Request to sleep 1 second exceeded the current timeout threshold\n'
        )
Example #2
0
    def run(*popenargs, **kwargs):
        timeout = kwargs.pop('timeout', None)

        with Timeout.DisableAlarm():
            current_time = time.time()
            Timeout.check(current_time=current_time)
            difference = Timeout.difference(current_time=current_time)

            if difference:
                timeout = min(timeout or sys.maxsize, int(math.ceil(difference)))
            return subprocess.run(*popenargs, timeout=timeout, **kwargs)
Example #3
0
    def run(*popenargs, **kwargs):
        timeout = kwargs.pop('timeout', None)
        capture_output = kwargs.pop('capture_output', False)

        with Timeout.DisableAlarm():
            current_time = time.time()
            Timeout.check(current_time=current_time)
            difference = Timeout.difference(current_time=current_time)

            if difference:
                timeout = min(timeout or sys.maxsize, int(math.ceil(difference)))
            if capture_output:
                if ('stdout' in kwargs) or ('stderr' in kwargs):
                    raise ValueError('stdout and stderr arguments may not be used with capture_output.')
                kwargs['stdout'] = subprocess.PIPE
                kwargs['stderr'] = subprocess.PIPE
            return subprocess.run(*popenargs, timeout=timeout, **kwargs)