Search in sources :

Example 1 with Py4JNetworkException

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;
}
Also used : Py4JNetworkException(py4j.Py4JNetworkException) IOException(java.io.IOException) GatewayServer(py4j.GatewayServer)

Aggregations

IOException (java.io.IOException)1 GatewayServer (py4j.GatewayServer)1 Py4JNetworkException (py4j.Py4JNetworkException)1