I have a Python server that I start with a Java ProcessBuilder thread. The Java program should wait until the server is ready before proceeding. When the server is ready, it outputs a "Server-ready" message, which I assume is picked up by the Process object's InputStream.
START_SERVER_COMMAND = TAGGERFLOW_HOME + "server.py";
server = new ProcessBuilder().inheritIO().command("python", START_SERVER_COMMAND, "" + portNum,
config.featOrderName(), config.childOrderName(), "" + maxBeta).start();
System.out.println("Hypertagger server started");
LOGGER.log(Level.INFO, "Hypertagger server started");
String line = null;
while(line == null) {
line = new BufferedReader(new InputStreamReader(server.getInputStream())).readLine();
if(line == null)
Thread.sleep(5000);
}
System.out.println("Exit loop");
However, line
is always null, and so Java never exits the loop. That most likely indicates that my assumption about the InputStream picking up the "Server-ready" message is wrong, but I don't know why that would be the case.
I'm looking for either a way to pick up the "Server-ready" message or a better way to detect when the server is ready. Any help would be appreciated.
EDIT
Before this, I tried initializing the BufferedReader before the loop. It had the same behavior.