Skip to content

Commit cf4f901

Browse files
committed
[SPARK-8763] backport process.check_output function from Python 2.7
1 parent 9765241 commit cf4f901

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

python/run-tests.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@
3131
import Queue
3232
else:
3333
import queue as Queue
34+
if sys.version_info >= (2, 7):
35+
subprocess_check_output = subprocess.check_output
36+
else:
37+
# SPARK-8763
38+
# backported from subprocess module in Python 2.7
39+
def subprocess_check_output(*popenargs, **kwargs):
40+
if 'stdout' in kwargs:
41+
raise ValueError('stdout argument not allowed, it will be overridden.')
42+
process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs)
43+
output, unused_err = process.communicate()
44+
retcode = process.poll()
45+
if retcode:
46+
cmd = kwargs.get("args")
47+
if cmd is None:
48+
cmd = popenargs[0]
49+
raise subprocess.CalledProcessError(retcode, cmd, output=output)
50+
return output
3451

3552

3653
# Append `SPARK_HOME/dev` to the Python path so that we can import the sparktestsupport module
@@ -156,11 +173,11 @@ def main():
156173

157174
task_queue = Queue.Queue()
158175
for python_exec in python_execs:
159-
python_implementation = subprocess.check_output(
176+
python_implementation = subprocess_check_output(
160177
[python_exec, "-c", "import platform; print(platform.python_implementation())"],
161178
universal_newlines=True).strip()
162179
LOGGER.debug("%s python_implementation is %s", python_exec, python_implementation)
163-
LOGGER.debug("%s version is: %s", python_exec, subprocess.check_output(
180+
LOGGER.debug("%s version is: %s", python_exec, subprocess_check_output(
164181
[python_exec, "--version"], stderr=subprocess.STDOUT, universal_newlines=True).strip())
165182
for module in modules_to_test:
166183
if python_implementation not in module.blacklisted_python_implementations:

0 commit comments

Comments
 (0)