You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@linkis.apache.org by al...@apache.org on 2022/05/31 03:38:43 UTC

[incubator-linkis] branch dev-1.1.3 updated: [Feature-2174] Add py4j watchdog thread to monitor java process (#2175)

This is an automated email from the ASF dual-hosted git repository.

alexkun pushed a commit to branch dev-1.1.3
in repository https://gitbox.apache.org/repos/asf/incubator-linkis.git


The following commit(s) were added to refs/heads/dev-1.1.3 by this push:
     new d2aa30cc1 [Feature-2174] Add py4j watchdog thread to monitor java process (#2175)
d2aa30cc1 is described below

commit d2aa30cc1ecfd2eda65ebc5da0f854dc8a12bf88
Author: peacewong <wp...@gmail.com>
AuthorDate: Tue May 31 11:38:38 2022 +0800

    [Feature-2174] Add py4j watchdog thread to monitor java process (#2175)
    
    * Add the py4j watchdog thread, if java exits python also exits immediately
    
    * update watchdog thread to daemon
---
 .../python/src/main/resources/python/python.py           | 16 ++++++++++++++++
 .../spark/src/main/resources/python/mix_pyspark.py       | 16 ++++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/linkis-engineconn-plugins/engineconn-plugins/python/src/main/resources/python/python.py b/linkis-engineconn-plugins/engineconn-plugins/python/src/main/resources/python/python.py
index 7533df496..d8df20ae4 100644
--- a/linkis-engineconn-plugins/engineconn-plugins/python/src/main/resources/python/python.py
+++ b/linkis-engineconn-plugins/engineconn-plugins/python/src/main/resources/python/python.py
@@ -39,6 +39,9 @@ try:
 except ImportError:
   from io import StringIO
 
+import time
+import threading
+
 # for back compatibility
 
 class Logger(object):
@@ -180,6 +183,19 @@ __show__._setup_matplotlib()
 
 intp.onPythonScriptInitialized(os.getpid())
 
+def java_watchdog_thread(sleep=10):
+    while True :
+        time.sleep(sleep)
+        try:
+            intp.kind()
+        except Exception as e:
+            print("Failed to detect java daemon, now exit python process")
+            print(e)
+            sys.exit(1)
+watchdog_thread = threading.Thread(target=java_watchdog_thread)
+watchdog_thread.setDaemon(True)
+watchdog_thread.start()
+
 while True :
   req = intp.getStatements()
   if req == None:
diff --git a/linkis-engineconn-plugins/engineconn-plugins/spark/src/main/resources/python/mix_pyspark.py b/linkis-engineconn-plugins/engineconn-plugins/spark/src/main/resources/python/mix_pyspark.py
index 627f33d43..c7093c4d8 100644
--- a/linkis-engineconn-plugins/engineconn-plugins/spark/src/main/resources/python/mix_pyspark.py
+++ b/linkis-engineconn-plugins/engineconn-plugins/spark/src/main/resources/python/mix_pyspark.py
@@ -41,6 +41,9 @@ try:
 except ImportError:
   from io import StringIO
 
+import time
+import threading
+
 # for back compatibility
 from pyspark.sql import SQLContext, HiveContext, Row
 
@@ -211,6 +214,19 @@ class UDF(object):
 udf = UDF(intp, sqlc)
 intp.onPythonScriptInitialized(os.getpid())
 
+def java_watchdog_thread(sleep=10):
+    while True :
+        time.sleep(sleep)
+        try:
+            intp.getKind()
+        except Exception as e:
+            print("Failed to detect java daemon, now exit python process")
+            print(e)
+            sys.exit(1)
+watchdog_thread = threading.Thread(target=java_watchdog_thread)
+watchdog_thread.setDaemon(True)
+watchdog_thread.start()
+
 while True :
     req = intp.getStatements()
     try:


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@linkis.apache.org
For additional commands, e-mail: commits-help@linkis.apache.org