Exemple #1
0
    def receive(self, blocking=True):
        with Timeout.DisableAlarm():
            if not blocking:
                return self.incoming.get(block=False)

            difference = Timeout.difference()
            if difference is not None:
                return self.incoming.get(timeout=difference)
            return self.incoming.get()
Exemple #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)
Exemple #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)