detect if H2O instance is already running in R

2.1k views Asked by At

This relates to the h2o package in R. I'm working with multiple jobs running in parallel, some may come in later than others. Is it possible to detect whether a h2o instance already exists and make a connection to that instance.

I see that if I know an instance is already running, i just do h2o.init(startH2O=FALSE), but what if I don't know that?

3

There are 3 answers

2
Darren Cook On

Just do h2o.init(startH2O=FALSE) and if it fails you know it wasn't running.

(Alternatively, you could make your own curl request to port 54321, and see if there is a reply.)

When you say "multiple jobs running in parallel", do you mean one instance of H2O, and it is making 2+ models at the same time? Or do you mean you are running 2+ instances of H2O, on a single machine, on different ports? If the latter, give the port number of interest to your h2o.init() call (but make sure you use the most recent version, the port arg was ignored until Nov 18th 2016: https://github.com/h2oai/h2o-3/pull/401 )

0
Aman J On

If you are looking for a way to just check the status without getting an error or exiting the script, you can use trycatch to achieve it.

assign("is_h2o_running", T, .GlobalEnv)

tryCatch(
    
    expr = {
        h2o.init(startH2O=FALSE)
    },
    error = function(e){ 
        print(e)
        assign("is_h2o_running", F, .GlobalEnv)
    },
    warning = function(w){
        print(w)
    }
)

print(paste0("Is H2O running : ", is_h2o_running))
0
Pouya BCD On

This is what you see if you try h2o.init(start_h2o=False) in Python. "Warning: if you don't want to start local H2O server, then use of h2o.connect() is preferred."