use of py4j.Py4JNetworkException in project cdap by caskdata.
the class AbstractSparkPythonUtil method startPy4jGateway.
/**
* Starts a Py4j gateway server.
*
* @param portFile the file to have the gateway server listening port (in string format) written to
* @return the gateway server
* @throws IOException if failed to start the server or failed to write out the port.
*/
public static GatewayServer startPy4jGateway(Path portFile) throws IOException {
GatewayServer server = new GatewayServer(null, 0);
try {
server.start();
} catch (Py4JNetworkException e) {
throw new IOException(e);
}
// Write the port number in string form to the port file
Files.write(portFile, Integer.toString(server.getListeningPort()).getBytes(StandardCharsets.UTF_8));
return server;
}
Aggregations