Revision: f5008a50a4ad
Branch:   default
Author:   Pekka Klärck
Date:     Tue May 20 08:20:51 2014 UTC
Log:      Process: Close standard streams after process has completed.

Update issue 1700
Status: Done
Fixed the problem by changing `close_custom_streams` method to close
also standard streams. Obviously also dropped `custom` from the method
name. The implementation is a bit longer than necessary, but wanted to
make it as explicit as possible. For example, reading streams by just
accessing `self.stdout` or `self.stderr` seemed a bit magic.

We alraedy had tests for running multiple processes both using default
(i.e. standard) and custom streams. They only executed 42 processes
which wasn't enough to trigger the problem. Now they run 500 which
seems to be enough. Don't want to make that unnecessarily large number
to avoid increasing test execution time.
http://code.google.com/p/robotframework/source/detail?r=f5008a50a4ad

Modified:
 /atest/testdata/standard_libraries/process/stdout_and_stderr.txt
 /src/robot/libraries/Process.py

=======================================
--- /atest/testdata/standard_libraries/process/stdout_and_stderr.txt Tue Jan 28 23:10:45 2014 UTC +++ /atest/testdata/standard_libraries/process/stdout_and_stderr.txt Tue May 20 08:20:51 2014 UTC
@@ -53,12 +53,12 @@

 Run multiple times
     [Tags]    performance
-    :FOR    ${i}    IN RANGE    42
+    :FOR    ${i}    IN RANGE    500
     \   Run And Test Once    ${i}

 Run multiple times using custom streams
     [Tags]    performance
-    :FOR    ${i}    IN RANGE    42
+    :FOR    ${i}    IN RANGE    500
     \   Run And Test Once    ${i}    ${STDOUT}    ${STDERR}


=======================================
--- /src/robot/libraries/Process.py     Thu Apr 17 12:04:02 2014 UTC
+++ /src/robot/libraries/Process.py     Tue May 20 08:20:51 2014 UTC
@@ -456,7 +456,7 @@
     def _wait(self, process):
         result = self._results[process]
         result.rc = process.wait() or 0
-        result.close_custom_streams()
+        result.close_streams()
         logger.info('Process completed.')
         return result

@@ -749,22 +749,20 @@
     @property
     def stdout(self):
         if self._stdout is None:
-            self._stdout = self._read_stream(self.stdout_path,
-                                             self._process.stdout)
+            self._read_stdout()
         return self._stdout

     @property
     def stderr(self):
         if self._stderr is None:
-            self._stderr = self._read_stream(self.stderr_path,
-                                             self._process.stderr)
+            self._read_stderr()
         return self._stderr

-    def close_custom_streams(self):
-        for stream in self._custom_streams:
-            if not stream.closed:
-                stream.flush()
-                stream.close()
+    def _read_stdout(self):
+ self._stdout = self._read_stream(self.stdout_path, self._process.stdout)
+
+    def _read_stderr(self):
+ self._stderr = self._read_stream(self.stderr_path, self._process.stderr)

     def _read_stream(self, stream_path, stream):
         if stream_path:
@@ -780,6 +778,21 @@
             output = output[:-1]
         return decode_output(output, force=True)

+    def close_streams(self):
+ standard_streams = self._get_and_read_standard_streams(self._process)
+        for stream in standard_streams + self._custom_streams:
+            if stream and not stream.closed:
+                stream.flush()
+                stream.close()
+
+    def _get_and_read_standard_streams(self, process):
+ stdin, stdout, stderr = process.stdin, process.stdout, process.stderr
+        if stdout:
+            self._read_stdout()
+        if stderr:
+            self._read_stderr()
+        return [stdin, stdout, stderr]
+
     def __str__(self):
         return '<result object with rc %d>' % self.rc

--

--- 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/d/optout.

Reply via email to