Github user squito commented on a diff in the pull request:
https://github.com/apache/spark/pull/22247#discussion_r213469645
--- Diff: python/pyspark/java_gateway.py ---
@@ -147,6 +147,39 @@ def do_server_auth(conn, auth_secret):
raise Exception("Unexpected reply from iterator server.")
+def local_connect_and_auth(port, auth_secret):
+ """
+ Connect to local host, authenticate with it, and return a
(sockfile,sock) for that connection.
+ Handles IPV4 & IPV6, does some error handling.
+ :param port
+ :param auth_secret
+ :return: a tuple with (sockfile, sock)
+ """
+ sock = None
+ errors = []
+ # Support for both IPv4 and IPv6.
+ # On most of IPv6-ready systems, IPv6 will take precedence.
+ for res in socket.getaddrinfo("127.0.0.1", port, socket.AF_UNSPEC,
socket.SOCK_STREAM):
+ af, socktype, proto, _, sa = res
+ sock = socket.socket(af, socktype, proto)
+ try:
+ sock.settimeout(15)
+ sock.connect(sa)
+ except socket.error as e:
+ emsg = _exception_message(e)
+ errors.append("tried to connect to %s, but an error occured:
%s" % (sa, emsg))
+ sock.close()
+ sock = None
+ continue
+ break
--- End diff --
done
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]