Skip to content

Commit

Permalink
Python server IO logged to standard out by default.
Browse files Browse the repository at this point in the history
Set the destination of input, output, and error logs for remote servers same as Java process.

PiperOrigin-RevId: 551642169
Change-Id: Ibdb2219723bc983c3e2200f9f398f5be599ac196
  • Loading branch information
nttran8 authored and copybara-github committed Jul 27, 2023
1 parent d9218fa commit 231018c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@ public Process execute(Executor executor)
return process;
}

/**
* Starts the command and asynchronously collect output and error.
*
* @return Started {@link Process} object.
* @throws IOException if an I/O error occurs when starting the command executing process.
* @throws InterruptedException if interrupted while waiting for the command's output.
* @throws ExecutionException if the command execution failed.
*/
public Process executeAsync() throws IOException, InterruptedException, ExecutionException {
logger.atInfo().log("Executing the following command: '%s'", COMMAND_ARGS_JOINER.join(args));
process = processBuilder.inheritIO().start();
return process;
}

/**
* Starts the command without collecting output and error streams.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ public void execute_always_startsProcessAndReturnsProcessInstance()
assertThat(process.exitValue()).isEqualTo(0);
}

@Test
public void executeAsync_always_startsProcessAndReturnsProcessInstance()
throws IOException, InterruptedException, ExecutionException {
CommandExecutor executor = new CommandExecutor("/bin/sh", "-c", "echo 1");

Process process = executor.executeAsync();
process.waitFor();

assertThat(process.exitValue()).isEqualTo(0);
}

@Test
public void executeWithNoStreamCollection_always_startsProcessAndReturnsProcessInstance()
throws IOException, InterruptedException, ExecutionException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private String getCommand(String flag, Object command) {

private Optional<Process> runProcess(CommandExecutor executor) {
try {
return Optional.of(executor.executeWithNoStreamCollection());
return Optional.of(executor.executeAsync());
} catch (IOException | InterruptedException | ExecutionException e) {
logger.atWarning().withCause(e).log("Could not execute language server binary.");
}
Expand Down
1 change: 1 addition & 0 deletions plugin_server/py/plugin_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,5 @@ def _configure_health_service(server):


if __name__ == '__main__':
flags.set_default(logging.ALSOLOGTOSTDERR, True)
app.run(main)

0 comments on commit 231018c

Please sign in to comment.