systemml-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [systemml] mboehm7 commented on a change in pull request #900: [SYSTEMDS-310] Python API Refactor
Date Tue, 05 May 2020 11:17:59 GMT

mboehm7 commented on a change in pull request #900:
URL: https://github.com/apache/systemml/pull/900#discussion_r420033904



##########
File path: src/main/java/org/apache/sysds/api/PythonDMLScript.java
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.sysds.api;
+
+import java.util.concurrent.BrokenBarrierException;
+import java.util.concurrent.CyclicBarrier;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.sysds.api.jmlc.Connection;
+
+import py4j.GatewayServer;
+
+public class PythonDMLScript {
+	private static final Log LOG = LogFactory.getLog(PythonDMLScript.class.getName());
+	private Connection _connection;
+
+	/**
+	 * Entry point for Python API.
+	 * 
+	 * The system returns with exit code 1, if the startup process fails, and 0 if the startup
was successful.
+	 * 
+	 * @param args Command line arguments.
+	 */
+	public static void main(String[] args) {
+		System.exit((start(args[0])) ? 0 : 1);
+	}
+
+	private static boolean start(String port) {
+		try {
+			// TODO Add argument parsing here.
+			GatewayServer GwS = new GatewayServer(new PythonDMLScript(), Integer.parseInt(port));
+			// GwS is non blocking, if first argument is true then it becomes blocking,
+			// but then the python process will not know when the JVM instance is ready.
+			GwS.start();
+			// message the python interface that the JVM is ready.
+			System.out.println("GatewayServer Started");
+
+			// Hack block this process until python stops the gateway.
+			// https://stackoverflow.com/questions/30845546/how-can-we-make-a-thread-to-sleep-for-a-infinite-time-in-java#30845606
+			new CyclicBarrier(2).await();

Review comment:
       Maybe we could add a `GatewayServerListener` which in its `serverPostShutdown` simply
calls a `notify` on a monitor we `wait` on 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:
users@infra.apache.org



Mime
View raw message