dianfu commented on a change in pull request #11749:
[FLINK-16669][python][table] Support Python UDF in SQL function DDL.
URL: https://github.com/apache/flink/pull/11749#discussion_r409262374
##########
File path:
flink-python/src/main/java/org/apache/flink/client/python/PythonEnvUtils.java
##########
@@ -247,4 +257,90 @@ static Process startPythonProcess(PythonEnvironment
pythonEnv, List<String> comm
return process;
}
+
+ static void shutdownPythonProcess(Process pythonProcess, long
timeoutMillis) {
+ pythonProcess.destroy();
+ try {
+ pythonProcess.waitFor(timeoutMillis,
TimeUnit.MILLISECONDS);
+ } catch (InterruptedException e) {
+ throw new RuntimeException("Interrupt while waiting for
the python process to stop.", e);
+ }
+ if (pythonProcess.isAlive()) {
+ pythonProcess.destroyForcibly();
+ }
+ }
+
+ private static int findFreePort() throws IOException {
+ ServerSocket socket = new ServerSocket(0);
+ int port = socket.getLocalPort();
+ socket.close();
+ return port;
+ }
+
+ /**
+ * Creates a GatewayServer run in a daemon thread.
+ *
+ * @return The created GatewayServer
+ */
+ static GatewayServer startGatewayServer() throws ExecutionException,
InterruptedException {
+ CompletableFuture<GatewayServer> gatewayServer = new
CompletableFuture<>();
+ Thread thread = new Thread(() -> {
+ int freePort;
+ try {
+ freePort = findFreePort();
+ } catch (IOException e) {
+ throw new RuntimeException("Could not find a
free port for Py4jCallbackClient.");
Review comment:
We should catch the exception and complete gatewayServerFuture using
`completeExceptionally`when encountering exceptions.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services