h2o-py/h2o/backend/server.py
def _launch_server(self, port, baseport, mmax, mmin, ea, nthreads, jvm_custom_args, bind_to_localhost, log_dir=None, log_level=None):
        """Actually start the h2o.jar executable (helper method for `.start()`)."""
        self._ip = "127.0.0.1"

        # Find Java and check version. (Note that subprocess.check_output returns the output as a bytes object)
        java = self._find_java()
        self._check_java(java, self._verbose)

        if self._verbose:
            print("  Starting server from " + self._jar_path)
            print("  Ice root: " + self._ice_root)

        # Combine jar path with the optional extra classpath
        classpath = [self._jar_path] if self._extra_classpath is None else [self._jar_path] + self._extra_classpath

        # Construct java command to launch the process
        cmd = [java]

        # ...add JVM options
        cmd += ["-ea"] if ea else []
        for (mq, num) in [("-Xms", mmin), ("-Xmx", mmax)]:
            if num is None: continue
            numstr = "%dG" % (num >> 30) if num == (num >> 30) << 30 else \
                     "%dM" % (num >> 20) if num == (num >> 20) << 20 else \
                     str(num)
            cmd += [mq + numstr]
        if jvm_custom_args is not None:
            for arg in jvm_custom_args:
                assert type(arg) is str
                cmd += [arg]

        cmd += ["-cp", os.pathsep.join(classpath), "water.H2OApp"]  # This should be the last JVM option

        # ...add H2O options
        cmd += ["-ip", self._ip]
        if bind_to_localhost:
            cmd += ["-web_ip", self._ip]
        cmd += ["-port", str(port)] if port else []
        cmd += ["-baseport", str(baseport)] if baseport else []
        cmd += ["-ice_root", self._ice_root]
        cmd += ["-nthreads", str(nthreads)] if nthreads > 0 else []

        if log_dir:
            cmd += ["-log_dir", log_dir]

        if log_level:
            cmd += ["-log_level", log_level]

        if not self._name:
            self._name = "H2O_from_python_%s" % self._tmp_file("salt")
        cmd += ["-name", self._name]

        # Warning: do not change to any higher log-level, otherwise we won't be able to know which port the
        # server is listening to.
        cmd += ["-log_level", "INFO"]

        # Create stdout and stderr files
        self._stdout = self._tmp_file("stdout")
        self._stderr = self._tmp_file("stderr")
        cwd = os.path.abspath(os.getcwd())
        out = open(self._stdout, "w")
        err = open(self._stderr, "w")
        if self._verbose:
            print("  JVM stdout: " + out.name)
            print("  JVM stderr: " + err.name)

        # Launch the process
        win32 = sys.platform == "win32"
        flags = getattr(subprocess, "CREATE_NEW_PROCESS_GROUP", 0) if win32 else 0
        prex = os.setsid if not win32 else None
        try:
            proc = subprocess.Popen(args=cmd, stdout=out, stderr=err, cwd=cwd, creationflags=flags, preexec_fn=prex)
        except OSError as e:
            traceback = getattr(e, "child_traceback", None)
            raise H2OServerError("Unable to start server: %s" % e, traceback)

        # Wait until the server is up-and-running
        giveup_time = time.time() + self._TIME_TO_START
        while True:
            if proc.poll() is not None:
                raise H2OServerError("Server process terminated with error code %d" % proc.returncode)
            ret = self._get_server_info_from_logs()
            if ret:
                self._scheme = ret[0]
                self._ip = ret[1]
                self._port = ret[2]
                self._process = proc
                break
            if time.time() > giveup_time:
                elapsed_time = time.time() - (giveup_time - self._TIME_TO_START)
                raise H2OServerError("Server wasn't able to start in %f seconds." % elapsed_time)
            time.sleep(0.2)
def _launch_server(self, port, baseport, mmax, mmin, ea, nthreads, jvm_custom_args, bind_to_localhost, log_dir=None, log_level=None):
        """Actually start the h2o.jar executable (helper method for `.start()`)."""
        self._ip = "127.0.0.1"

        # Find Java and check version. (Note that subprocess.check_output returns the output as a bytes object)
        java = self._find_java()
        self._check_java(java, self._verbose)

        if self._verbose:
            print("  Starting server from " + self._jar_path)
            print("  Ice root: " + self._ice_root)

        # Combine jar path with the optional extra classpath
        classpath = [self._jar_path] if self._extra_classpath is None else [self._jar_path] + self._extra_classpath

        # Construct java command to launch the process
        cmd = [java]

        # ...add JVM options
        cmd += ["-ea"] if ea else []
        for (mq, num) in [("-Xms", mmin), ("-Xmx", mmax)]:
            if num is None: continue
            numstr = "%dG" % (num >> 30) if num == (num >> 30) << 30 else \
                     "%dM" % (num >> 20) if num == (num >> 20) << 20 else \
                     str(num)
            cmd += [mq + numstr]
        if jvm_custom_args is not None:
            for arg in jvm_custom_args:
                assert type(arg) is str
                cmd += [arg]

        cmd += ["-cp", os.pathsep.join(classpath), "water.H2OApp"]  # This should be the last JVM option

        # ...add H2O options
        cmd += ["-ip", self._ip]
        if bind_to_localhost:
            cmd += ["-web_ip", self._ip]
        cmd += ["-port", str(port)] if port else []
        cmd += ["-baseport", str(baseport)] if baseport else []
        cmd += ["-ice_root", self._ice_root]
        cmd += ["-nthreads", str(nthreads)] if nthreads > 0 else []

        if log_dir:
            cmd += ["-log_dir", log_dir]

        if log_level:
            cmd += ["-log_level", log_level]

        if not self._name:
            self._name = "H2O_from_python_%s" % self._tmp_file("salt")
        cmd += ["-name", self._name]

        # Warning: do not change to any higher log-level, otherwise we won't be able to know which port the
        # server is listening to.
        cmd += ["-log_level", "INFO"]

        # Create stdout and stderr files
        self._stdout = self._tmp_file("stdout")
        self._stderr = self._tmp_file("stderr")
        cwd = os.path.abspath(os.getcwd())
        out = open(self._stdout, "w")
        err = open(self._stderr, "w")
        if self._verbose:
            print("  JVM stdout: " + out.name)
            print("  JVM stderr: " + err.name)

        # Launch the process
        win32 = sys.platform == "win32"
        flags = getattr(subprocess, "CREATE_NEW_PROCESS_GROUP", 0) if win32 else 0
        prex = os.setsid if not win32 else None
        try:
            proc = subprocess.Popen(args=cmd, stdout=out, stderr=err, cwd=cwd, creationflags=flags, preexec_fn=prex)
        except OSError as e:
            traceback = getattr(e, "child_traceback", None)
            raise H2OServerError("Unable to start server: %s" % e, traceback)

        # Wait until the server is up-and-running
        giveup_time = time.time() + self._TIME_TO_START
        while True:
            if proc.poll() is not None:
                raise H2OServerError("Server process terminated with error code %d" % proc.returncode)
            ret = self._get_server_info_from_logs()
            if ret:
                self._scheme = ret[0]
                self._ip = ret[1]
                self._port = ret[2]
                self._process = proc
                break
            if time.time() > giveup_time:
                elapsed_time = time.time() - (giveup_time - self._TIME_TO_START)
                raise H2OServerError("Server wasn't able to start in %f seconds." % elapsed_time)
            time.sleep(0.2)
def _launch_server ( self , port , baseport , mmax , mmin , ea , nthreads , jvm_custom_args , bind_to_localhost , log_dir = None , log_level = None ) : self . _ip = "127.0.0.1" # Find Java and check version. (Note that subprocess.check_output returns the output as a bytes object) java = self . _find_java ( ) self . _check_java ( java , self . _verbose ) if self . _verbose : print ( "  Starting server from " + self . _jar_path ) print ( "  Ice root: " + self . _ice_root ) # Combine jar path with the optional extra classpath classpath = [ self . _jar_path ] if self . _extra_classpath is None else [ self . _jar_path ] + self . _extra_classpath # Construct java command to launch the process cmd = [ java ] # ...add JVM options cmd += [ "-ea" ] if ea else [ ] for ( mq , num ) in [ ( "-Xms" , mmin ) , ( "-Xmx" , mmax ) ] : if num is None : continue numstr = "%dG" % ( num >> 30 ) if num == ( num >> 30 ) << 30 else "%dM" % ( num >> 20 ) if num == ( num >> 20 ) << 20 else str ( num ) cmd += [ mq + numstr ] if jvm_custom_args is not None : for arg in jvm_custom_args : assert type ( arg ) is str cmd += [ arg ] cmd += [ "-cp" , os . pathsep . join ( classpath ) , "water.H2OApp" ] # This should be the last JVM option # ...add H2O options cmd += [ "-ip" , self . _ip ] if bind_to_localhost : cmd += [ "-web_ip" , self . _ip ] cmd += [ "-port" , str ( port ) ] if port else [ ] cmd += [ "-baseport" , str ( baseport ) ] if baseport else [ ] cmd += [ "-ice_root" , self . _ice_root ] cmd += [ "-nthreads" , str ( nthreads ) ] if nthreads > 0 else [ ] if log_dir : cmd += [ "-log_dir" , log_dir ] if log_level : cmd += [ "-log_level" , log_level ] if not self . _name : self . _name = "H2O_from_python_%s" % self . _tmp_file ( "salt" ) cmd += [ "-name" , self . _name ] # Warning: do not change to any higher log-level, otherwise we won't be able to know which port the # server is listening to. cmd += [ "-log_level" , "INFO" ] # Create stdout and stderr files self . _stdout = self . _tmp_file ( "stdout" ) self . _stderr = self . _tmp_file ( "stderr" ) cwd = os . path . abspath ( os . getcwd ( ) ) out = open ( self . _stdout , "w" ) err = open ( self . _stderr , "w" ) if self . _verbose : print ( "  JVM stdout: " + out . name ) print ( "  JVM stderr: " + err . name ) # Launch the process win32 = sys . platform == "win32" flags = getattr ( subprocess , "CREATE_NEW_PROCESS_GROUP" , 0 ) if win32 else 0 prex = os . setsid if not win32 else None try : proc = subprocess . Popen ( args = cmd , stdout = out , stderr = err , cwd = cwd , creationflags = flags , preexec_fn = prex ) except OSError as e : traceback = getattr ( e , "child_traceback" , None ) raise H2OServerError ( "Unable to start server: %s" % e , traceback ) # Wait until the server is up-and-running giveup_time = time . time ( ) + self . _TIME_TO_START while True : if proc . poll ( ) is not None : raise H2OServerError ( "Server process terminated with error code %d" % proc . returncode ) ret = self . _get_server_info_from_logs ( ) if ret : self . _scheme = ret [ 0 ] self . _ip = ret [ 1 ] self . _port = ret [ 2 ] self . _process = proc break if time . time ( ) > giveup_time : elapsed_time = time . time ( ) - ( giveup_time - self . _TIME_TO_START ) raise H2OServerError ( "Server wasn't able to start in %f seconds." % elapsed_time ) time . sleep ( 0.2 )
Actually start the h2o.jar executable (helper method for `.start()`).
Actually start the h2o . jar executable ( helper method for . start () ) .