Skip to content

Commit fdcad6e

Browse files
cocoatomoDavies Liu
authored andcommitted
[SPARK-8763] [PYSPARK] executing run-tests.py with Python 2.6 fails with absence of subprocess.check_output function
Running run-tests.py with Python 2.6 cause following error: ``` Running PySpark tests. Output is in python//Users/tomohiko/.jenkins/jobs/pyspark_test/workspace/python/unit-tests.log Will test against the following Python executables: ['python2.6', 'python3.4', 'pypy'] Will test the following Python modules: ['pyspark-core', 'pyspark-ml', 'pyspark-mllib', 'pyspark-sql', 'pyspark-streaming'] Traceback (most recent call last): File "./python/run-tests.py", line 196, in <module> main() File "./python/run-tests.py", line 159, in main python_implementation = subprocess.check_output( AttributeError: 'module' object has no attribute 'check_output' ... ``` The cause of this error is using subprocess.check_output function, which exists since Python 2.7. (ref. https://docs.python.org/2.7/library/subprocess.html#subprocess.check_output) Author: cocoatomo <[email protected]> Closes apache#7161 from cocoatomo/issues/8763-test-fails-py26 and squashes the following commits: cf4f901 [cocoatomo] [SPARK-8763] backport process.check_output function from Python 2.7
1 parent 9765241 commit fdcad6e

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)