Avoid too many characters cached in buffer #798
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue Description
Recently, I've encountered an issue that the launch test (added with
add_ros_test
with a launch.py file) hangs indefinitely.After investigation, I found that it was stuck at the
getvalue
call of aStringIO
buffer:launch/launch/launch/actions/execute_local.py
Lines 391 to 396 in f3e9cfe
The root cause is that the
__on_process_output
method stores output in the buffer but does not process it, resulting in a huge buffer to begetvalue
on (and thus hangs):launch/launch/launch/actions/execute_local.py
Lines 378 to 385 in f3e9cfe
This happens because one of my noisy program prints to stdout without a line separator, causing the buffer to accumulate.
Proposed Improvement
This PR addresses the issue by ensuring the buffer does not store too many characters, which I think it is always not wrong.
Other Changes
os.linesep
to\n
since from the doc of StringIO, theStringIO
by default uses\n
as newline. Otherwise, writing lines with EOL='\n' in Windows will stop line from being processed.break
in the else clause; this is unnecessary, it will be the last line in the buffer if it does not end with the line separator.