WeiZhong94 commented on a change in pull request #14842:
URL: https://github.com/apache/flink/pull/14842#discussion_r569902739



##########
File path: 
flink-python/src/main/java/org/apache/flink/client/python/PythonFunctionFactoryImpl.java
##########
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.client.python;
+
+import org.apache.flink.table.functions.python.PythonFunction;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import java.io.Closeable;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/** Default implementation of PythonFunctionFactory. */
+public class PythonFunctionFactoryImpl implements PythonFunctionFactory, 
Closeable {
+
+    @Nonnull private final PythonFunctionFactory realPythonFunctionFactory;
+
+    @Nullable private final PythonProcessShutdownHook shutdownHook;
+
+    public PythonFunctionFactoryImpl(
+            PythonFunctionFactory realPythonFunctionFactory,
+            PythonProcessShutdownHook shutdownHook) {
+        this.realPythonFunctionFactory = 
checkNotNull(realPythonFunctionFactory);
+        this.shutdownHook = shutdownHook;
+    }
+
+    @Override
+    public PythonFunction getPythonFunction(String moduleName, String 
objectName) {
+        return realPythonFunctionFactory.getPythonFunction(moduleName, 
objectName);
+    }
+
+    @Override
+    public void close() {
+        if (shutdownHook != null) {
+            if (Runtime.getRuntime().removeShutdownHook(shutdownHook)) {
+                shutdownHook.start();

Review comment:
       We can call shutdownHook.run() directly so that the exceptions can be 
captured in current call stack.

##########
File path: 
flink-table/flink-table-common/src/main/java/org/apache/flink/table/functions/python/utils/PythonFunctionUtils.java
##########
@@ -39,15 +37,16 @@ public static PythonFunction getPythonFunction(
                             Thread.currentThread().getContextClassLoader());

Review comment:
       we can use the class loader in the parameter

##########
File path: 
flink-python/src/test/java/org/apache/flink/client/python/PythonFunctionFactoryTest.java
##########
@@ -56,6 +65,38 @@ public static void main(String[] args) throws Exception {
         cleanEnvironment();
     }
 
+    @Test
+    public void testCache() throws ExecutionException {
+        LoadingCache<String, String> cache =

Review comment:
       Maybe we can use `CacheKey` as the key of this test case?

##########
File path: 
flink-python/src/main/java/org/apache/flink/client/python/PythonFunctionFactory.java
##########
@@ -178,14 +199,44 @@ static void shutdownPythonProcess(Process pythonProcess, 
long timeoutMillis) {
     class PythonProcessShutdownHook extends Thread {
 
         private Process process;
+        private GatewayServer gatewayServer;
 
-        public PythonProcessShutdownHook(Process process) {
+        public PythonProcessShutdownHook(Process process, GatewayServer 
gatewayServer) {
             this.process = process;
+            this.gatewayServer = gatewayServer;
         }
 
         @Override
         public void run() {
-            shutdownPythonProcess(process, TIMEOUT_MILLIS);
+            try {
+                shutdownPythonProcess(process, TIMEOUT_MILLIS);
+            } finally {
+                gatewayServer.shutdown();
+            }
+        }
+    }
+
+    class CacheKey {

Review comment:
       We need add java doc here.




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to