From dev-return-3078-apmail-systemml-dev-archive=systemml.apache.org@systemml.apache.org Tue May 5 19:57:52 2020 Return-Path: X-Original-To: apmail-systemml-dev-archive@minotaur.apache.org Delivered-To: apmail-systemml-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by minotaur.apache.org (Postfix) with SMTP id 906EB192C1 for ; Tue, 5 May 2020 19:57:52 +0000 (UTC) Received: (qmail 8766 invoked by uid 500); 5 May 2020 19:57:52 -0000 Delivered-To: apmail-systemml-dev-archive@systemml.apache.org Received: (qmail 8743 invoked by uid 500); 5 May 2020 19:57:52 -0000 Mailing-List: contact dev-help@systemml.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@systemml.apache.org Delivered-To: mailing list dev@systemml.apache.org Received: (qmail 8730 invoked by uid 99); 5 May 2020 19:57:51 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 May 2020 19:57:51 +0000 From: =?utf-8?q?GitBox?= To: dev@systemml.apache.org Subject: =?utf-8?q?=5BGitHub=5D_=5Bsystemml=5D_Baunsgaard_commented_on_a_change_in_pu?= =?utf-8?q?ll_request_=23900=3A_=5BSYSTEMDS-310=5D_Python_API_Refactor?= Message-ID: <158870867183.26397.6545182952923951758.asfpy@gitbox.apache.org> Date: Tue, 05 May 2020 19:57:51 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit References: In-Reply-To: Baunsgaard commented on a change in pull request #900: URL: https://github.com/apache/systemml/pull/900#discussion_r420369567 ########## 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: Now changed to use that, thanks for the suggestion, absolutely the right call. ---------------------------------------------------------------- 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