Skip to content

Commit

Permalink
[utils/subprocess] bring back syntax improvements
Browse files Browse the repository at this point in the history
Needlessly reverted by the previous commit.
  • Loading branch information
degemer committed Mar 29, 2017
1 parent 801e0e5 commit 54a2999
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions utils/subprocess_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,28 @@
# Licensed under Simplified BSD License (see LICENSE)

# stdlib
from contextlib import nested
from functools import wraps
import logging
import subprocess
import tempfile

log = logging.getLogger(__name__)


class SubprocessOutputEmptyError(Exception):
pass

# FIXME: python 2.7 has a far better way to do this

def get_subprocess_output(command, log, raise_on_empty_output=True):
"""
Run the given subprocess command and return it's output. Raise an Exception
Run the given subprocess command and return its output. Raise an Exception
if an error occurs.
"""

# Use tempfile, allowing a larger amount of memory. The subprocess.Popen
# docs warn that the data read is buffered in memory. They suggest not to
# use subprocess.PIPE if the data size is large or unlimited.
with nested(tempfile.TemporaryFile(), tempfile.TemporaryFile()) as (stdout_f, stderr_f):

with tempfile.TemporaryFile() as stdout_f, tempfile.TemporaryFile() as stderr_f:
proc = subprocess.Popen(command, stdout=stdout_f, stderr=stderr_f)
proc.wait()
stderr_f.seek(0)
Expand Down

0 comments on commit 54a2999

Please sign in to comment.