Revision: 3098
Author: jprantan
Date: Tue Apr 27 05:57:54 2010
Log: Fixed signal monitoring to work correctly also with timeouts. Issue 108.
http://code.google.com/p/robotframework/source/detail?r=3098

Modified:
 /trunk/src/robot/running/handlers.py
 /trunk/src/robot/running/timeouts.py
 /trunk/src/robot/utils/error.py

=======================================
--- /trunk/src/robot/running/handlers.py        Tue Apr 27 03:45:29 2010
+++ /trunk/src/robot/running/handlers.py        Tue Apr 27 05:57:54 2010
@@ -90,31 +90,28 @@
                                                    output)
runner = self._runner_for(self._current_handler(), output, positional,
                                   named, self._get_timeout(namespace))
-        return self._run_handler_with_output_captured(runner, output)
+ return self._run_with_output_captured_and_signal_monitor(runner, output)

     def _runner_for(self, handler, output, positional, named, timeout):
-        wrapped_handler = self._wrap_with_signal_handling(handler)
         if timeout and timeout.active():
- return lambda: timeout.run(wrapped_handler, args=positional, kwargs=named, + return lambda: timeout.run(handler, args=positional, kwargs=named,
                                        logger=output)
-        return lambda: wrapped_handler(*positional, **named)
-
-    def _wrap_with_signal_handling(self, runnable):
-        def _wrapped_function(*wrapped_positional, **wrapped_named):
-            try:
-                STOP_SIGNAL_MONITOR.start_running_keyword()
-                return runnable(*wrapped_positional, **wrapped_named)
-            finally:
-                STOP_SIGNAL_MONITOR.stop_running_keyword()
-        return _wrapped_function
-
-    def _run_handler_with_output_captured(self, runner, output):
+        return lambda: handler(*positional, **named)
+
+    def _run_with_output_captured_and_signal_monitor(self, runner, output):
         utils.capture_output()
         try:
-            return runner()
+            return self._run_with_signal_monitoring(runner)
         finally:
             self._release_and_log_output(output)

+    def _run_with_signal_monitoring(self, runner):
+        try:
+            STOP_SIGNAL_MONITOR.start_running_keyword()
+            return runner()
+        finally:
+            STOP_SIGNAL_MONITOR.stop_running_keyword()
+
     def _release_and_log_output(self, logger):
         stdout, stderr = utils.release_output()
         logger.log_output(stdout)
@@ -189,8 +186,10 @@

 class _RunKeywordHandler(_PythonHandler):

-    def _wrap_with_signal_handling(self, runnable):
-        return runnable
+    def _run_with_signal_monitoring(self, runner):
+        # With run keyword variants, only the keyword to be run can fail
+        # and therefore monitoring should not raise exception yet.
+        return runner()

     def _parse_arguments(self, handler_method):
arg_index = RUN_KW_REGISTER.get_args_to_process(self.library.orig_name,
=======================================
--- /trunk/src/robot/running/timeouts.py        Tue Apr 27 03:45:29 2010
+++ /trunk/src/robot/running/timeouts.py        Tue Apr 27 05:57:54 2010
@@ -73,9 +73,11 @@
         if not self.active():
             raise FrameworkError('Timeout is not active')
         timeout = self.time_left()
+        STOP_SIGNAL_MONITOR.stop_running_keyword()
         if logger:
             logger.debug('%s timeout %s active. %s seconds left.'
% (self.type.capitalize(), self.string, round(timeout, 3)))
+        STOP_SIGNAL_MONITOR.start_running_keyword()
         if timeout <= 0:
             raise TimeoutError(self.get_message())
         notifier = Event()
@@ -88,7 +90,6 @@
         if runner.is_done():
             return runner.get_result()
         try:
-            STOP_SIGNAL_MONITOR.stop_running_keyword()
             thread.stop()
         except utils.RERAISED_EXCEPTIONS:
             raise
=======================================
--- /trunk/src/robot/utils/error.py     Tue Apr 27 03:55:29 2010
+++ /trunk/src/robot/utils/error.py     Tue Apr 27 05:57:54 2010
@@ -32,7 +32,7 @@
 _java_trace_re = re.compile('^\s+at (\w.+)')
 _ignored_java_trace = ('org.python.', 'robot.running.', 'robot$py.',
                        'sun.reflect.', 'java.lang.reflect.')
-_ignore_trace_until = (os.path.join('robot','running','handlers.py'), '_wrapped_function') +_ignore_trace_until = (os.path.join('robot','running','handlers.py'), '<lambda>') _generic_exceptions = ('AssertionError', 'AssertionFailedError', 'Exception',
                        'Error', 'RuntimeError', 'RuntimeException',
                        'DataError', 'TimeoutError', 'ExecutionFailed', 
'RemoteError')


--
Subscription settings: 
http://groups.google.com/group/robotframework-commit/subscribe?hl=en

Reply via email to