Skip to content

Commit 3870248

Browse files
committed
[SPARK-1466] Raise exception if pyspark Gateway process doesn't start.
If the gateway process fails to start correctly (e.g., because JAVA_HOME isn't set correctly, there's no Spark jar, etc.), right now pyspark fails because of a very difficult-to-understand error, where we try to parse stdout to get the port where Spark started and there's nothing there. This commit properly catches the error and throws an exception that includes the stderr output for much easier debugging. Thanks to @shivaram and @stogers for helping to fix this issue! Author: Kay Ousterhout <[email protected]> Closes #383 from kayousterhout/pyspark and squashes the following commits: 36dd54b [Kay Ousterhout] [SPARK-1466] Raise exception if Gateway process doesn't start.
1 parent dd96fcd commit 3870248

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

python/pyspark/java_gateway.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,19 @@ def launch_gateway():
4343
# Don't send ctrl-c / SIGINT to the Java gateway:
4444
def preexec_func():
4545
signal.signal(signal.SIGINT, signal.SIG_IGN)
46-
proc = Popen(command, stdout=PIPE, stdin=PIPE, preexec_fn=preexec_func)
46+
proc = Popen(command, stdout=PIPE, stdin=PIPE, stderr=PIPE, preexec_fn=preexec_func)
4747
else:
4848
# preexec_fn not supported on Windows
49-
proc = Popen(command, stdout=PIPE, stdin=PIPE)
50-
# Determine which ephemeral port the server started on:
51-
gateway_port = int(proc.stdout.readline())
49+
proc = Popen(command, stdout=PIPE, stdin=PIPE, stderr=PIPE)
50+
51+
try:
52+
# Determine which ephemeral port the server started on:
53+
gateway_port = int(proc.stdout.readline())
54+
except:
55+
error_code = proc.poll()
56+
raise Exception("Launching GatewayServer failed with exit code %d: %s" %
57+
(error_code, "".join(proc.stderr.readlines())))
58+
5259
# Create a thread to echo output from the GatewayServer, which is required
5360
# for Java log output to show up:
5461
class EchoOutputThread(Thread):

0 commit comments

Comments
 (0)