Comment #3 on issue 1481 by [email protected]: Wait For Process add
arguments "timeout=1m", "handleTimeout=Terminate Process"
http://code.google.com/p/robotframework/issues/detail?id=1481
Hi, in the past I used test frameworks, providing similar process
management functionality, for example SpawnWaitKill command of PerlACE.
I ported the known functionality to RF-Process library (patch attached),
incl acceptance tests.
The attached patch implements the command "Wait For Process Or Terminate".
If the process terminates in time, the return value is identical to "Wait
For Process" otherwise an optional pre_terminate_keyword is called with
process-handle as argument, and finally the process in question is
terminated and error is raised.
The "pre_terminate_Keyword" could be used to perform a screenshot before
terminating the process.
It would be great to see this feature in next release ;)
Comments are welcome.
def wait_for_process_or_terminate(self,
timeout,
retry_interval=0.2,
handle=None,
kill=False,
error_message='Process exceeded
timeout.',
pre_terminate_keyword=None):
"""Waits for the process to complete until timeout, otherwise
terminate and may raise error
The `retry_interval` frequence the process is polled.
If `handle`is not given, uses the current `active process`.
If `kill` is False the termination is smoothly, `True` will force
termination.
The `error_message` is the exception message
The `per_terminate_keyword` is called with process-handle as
argument before termination.
Returns a `result object` containing information about the
execution.
"""
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 = self.wait_for_process(handle)
return result
else:
## Otherwise terminate the process, wait and raise error
logger.info('Process exceeded %s timeout.' % str(timeout) )
if pre_terminate_keyword:
BuiltIn().get_library_instance('BuiltIn').run_keyword(pre_terminate_keyword,
handle)
self.terminate_process(handle, kill=kill) # send the
termination signal
result = self.wait_for_process(handle) # wait to release
the system resources
raise AssertionError(error_message)
Attachments:
wait_for_process_or_terminate.diff.tgz 1.7 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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.