Comment #6 on issue 1481 by frehb...@gmail.com: Wait For Process add arguments "timeout=1m", "handleTimeout=Terminate Process"
http://code.google.com/p/robotframework/issues/detail?id=1481

Hi,

a solution with optional timeout parameter might look like the following.
(diff attached, including 2 additional tests)

What do you think?

   def wait_for_process(self, handle=None, timeout=None):
        """Waits for the process to complete.

        If `handle` is not given, uses the current `active process`.
If `timeout` is not given, wait indefinitely for termination, otherwise fail after given timeout.

Returns a `result object` containing information about the execution.
        Fails if the timeout is defined and the process exceeds the timeout.
        """
        process = self._processes[handle]
        result = self._results[process]
        logger.info('Waiting for process to complete.')
        if not timeout:
            result.rc = process.wait() or 0
        else:
            retry_interval = 0.2  ## 200msec interval
            remaining_secs = timestr_to_secs(timeout)
            retry_timeout = timestr_to_secs(retry_interval)
            while self.is_process_running(handle) and remaining_secs > 0.0:
                remaining_secs -= retry_timeout
                time.sleep(retry_timeout)

            if remaining_secs > 0.0:
                ## Release the zombi process invoking 'wait'
                result.rc = process.wait() or 0
            else:
                ## Otherwise terminate the process, wait and raise error
                logger.info('Process exceeded %s timeout.' % str(timeout) )
                self.terminate_process(handle, kill=True) ## signal SIGKILL
result.rc = process.wait() ## zombi returns with SIGKILL value
                raise AssertionError('Process exceeded timeout.')

        logger.info('Process completed.')
        return result


Attachments:
        wait_for_process_with_timeout.diff.gz  1.4 KB

--
You received this message because this project is configured to send all issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

--

--- You received this message because you are subscribed to the Google Groups "robotframework-commit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to robotframework-commit+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to