Commit de7cfe9c authored by Charles Ferguson's avatar Charles Ferguson
Browse files

Update the streamedinput to ignore stderr.

The output on stderr being merged with the stdout was causing problems
when errors were output on that stream. We now have the option to
not write them out there.
parent 77be174e
......@@ -5,4 +5,6 @@ venv
venv3
.coverage
htmlcov
cover
coverage.xml
nosetests.xml
# Allow our testing
coverage==4.1
nose==1.3.7
psutil==4.3.0
# For linting
pylint==1.4.4
......
......@@ -29,7 +29,8 @@ echo '>>> Running tests'
passed=0
failed=0
for test in *_test.py ; do
if "$PYTHON_TOOL" "$test" -v ; then
if "$PYTHON_TOOL" "$test" -v \
--with-coverage --cover-branches --cover-html --cover-xml ; then
passed=$(($passed + 1))
else
failed=$(($failed + 1))
......
......@@ -73,10 +73,11 @@ class StreamedInput(object):
buffer_size = 0
stop_timeout = 0
stop_issued = False
keep_stderr = False
stdoutfd = 0
proc = None
def __init__(self, command, data_function=None, complete_function=None,
def __init__(self, command, data_function=None, complete_function=None, keep_stderr=False,
shell=False, buffer_size=1024 * 32, stop_timeout=10):
"""
Create an object which can run a subprocess and deliver its data to a function as it arrives.
......@@ -90,6 +91,7 @@ class StreamedInput(object):
@param data_function: Function to call with the received data (default: Accumulate data into
StreamedInput.data_buffer queue for reading with 'read' or iteration)
@param complete_function: Function to call when the subprocess completes (default: None)
@param keep_stderr: If the stderr is merged into the output.
@param shell: Whether a shell should be used (default: False)
@param buffer_size: Internal read buffer size
@param stop_timeout: Grace timeout for the subprocess to exit when told to terminate,
......@@ -106,6 +108,7 @@ class StreamedInput(object):
self.data_buffer = Queue.Queue()
self.stop_timeout = stop_timeout
self.stop_issued = False
self.keep_stderr = keep_stderr
# Function to call with data as it is received
self.data_function = data_function or self._simple_buffer_function
......@@ -163,9 +166,10 @@ class StreamedInput(object):
raise StreamedInputCannotStartError("Cannot start StreamedInput which has already been started")
try:
stderr = subprocess.STDOUT if self.keep_stderr else open(os.devnull, 'w')
self.proc = subprocess.Popen(self.command, shell=self.shell,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
stdout=subprocess.PIPE, stderr=stderr,
bufsize=0)
self.stdoutfd = self.proc.stdout.fileno()
self._set_nonblocking()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment