use of py4j.GatewayServer in project angel by Tencent.
the class PythonGatewayServer method startServer.
private void startServer() throws IOException {
GatewayServer gatewayServer = new GatewayServer(null, 0);
gatewayServer.start();
int boundPort = gatewayServer.getListeningPort();
if (boundPort == -1) {
LOG.error("GatewayServer failed to binding");
System.exit(1);
} else {
LOG.debug("GatewayServer started on port: " + boundPort);
}
String callbackHost = System.getenv("_PYANGEL_CALLBACK_HOST");
LOG.info("GatewayServer Host: " + callbackHost);
int callbackPort = Integer.parseInt(System.getenv("_PYANGEL_CALLBACK_PORT"));
LOG.info("GatewayServer Port: " + callbackPort);
try {
Socket callbackSocket = new Socket(callbackHost, callbackPort);
DataOutputStream dos = new DataOutputStream(callbackSocket.getOutputStream());
dos.writeInt(boundPort);
dos.close();
callbackSocket.close();
// Exit on EOF or broken pipe to ensure that this process dies when the Python driver dies:
while (System.in.read() != -1) {
// Do nothing
}
} catch (IOException ioe) {
LOG.error("failed to start callback server: ", ioe);
}
LOG.debug("Exiting due to broken pipe from Python");
System.exit(0);
}
use of py4j.GatewayServer in project Anserini by castorini.
the class PyseriniEntryPoint method main.
public static void main(String[] argv) throws Exception {
System.out.println("starting Gateway Server...");
GatewayServer gatewayServer = new GatewayServer(new PyseriniEntryPoint());
gatewayServer.start();
System.out.println("started!");
}
use of py4j.GatewayServer in project GeoGig by boundlessgeo.
the class SilentProgressListener method main.
public static void main(String[] args) {
Logging.tryConfigureLogging();
int port = GatewayServer.DEFAULT_PORT;
if (args.length != 0) {
if (args.length > 1) {
System.out.println("Too many arguments.\n Usage: geogig-gateway [port]");
return;
}
try {
port = Integer.parseInt(args[0]);
} catch (NumberFormatException e) {
System.out.println("Wrong argument: " + args[0] + "\nUsage: geogig-gateway [port]");
return;
}
}
GatewayServer gatewayServer = new GatewayServer(new GeogigPy4JEntryPoint(), port);
gatewayServer.start();
System.out.println("GeoGig server correctly started and waiting for conections at port " + Integer.toString(port));
}
use of py4j.GatewayServer 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;
}
use of py4j.GatewayServer in project flink by apache.
the class PythonEnvUtils method startGatewayServer.
/**
* Creates a GatewayServer run in a daemon thread.
*
* @return The created GatewayServer
*/
static GatewayServer startGatewayServer() throws ExecutionException, InterruptedException {
CompletableFuture<GatewayServer> gatewayServerFuture = new CompletableFuture<>();
Thread thread = new Thread(() -> {
try (NetUtils.Port port = NetUtils.getAvailablePort()) {
int freePort = port.getPort();
GatewayServer server = new GatewayServer.GatewayServerBuilder().gateway(new Gateway(new ConcurrentHashMap<String, Object>(), new CallbackClient(freePort))).javaPort(0).build();
resetCallbackClientExecutorService(server);
gatewayServerFuture.complete(server);
server.start(true);
} catch (Throwable e) {
gatewayServerFuture.completeExceptionally(e);
}
});
thread.setName("py4j-gateway");
thread.setDaemon(true);
thread.start();
thread.join();
return gatewayServerFuture.get();
}
Aggregations