Skip to content

Commit

Permalink
More fixes for prompt logger (#4075)
Browse files Browse the repository at this point in the history
Fixes #4074

We shouldn't sleep for `nonInteractivePromptUpdateIntervalMillis` every
time `readTerminalDims` fails, because that means if there's a transient
failure it doesn't check again for 60s during which there is no prompt
shown

Instead, we always check after `promptUpdateIntervalMillis` seconds, and
but only refresh the prompt if `now - lastUpdate >
nonInteractivePromptUpdateIntervalMillis`

Also we make sure we call `writeTerminalDims` at least once before we
start the Mill background process, rather than relying on the background
thread to reach that code path in time

Either of these fixes alone should solve the issue, but might as well do
both
  • Loading branch information
lihaoyi authored Dec 6, 2024
1 parent 60e6ce2 commit 46a199e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 22 deletions.
23 changes: 14 additions & 9 deletions main/util/src/mill/util/PromptLogger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,28 @@ private[mill] class PromptLogger(
if (enableTicker) refreshPrompt()

val promptUpdaterThread = new Thread(
() =>
() => {
var lastUpdate = System.currentTimeMillis()
while (!runningState.stopped) {
val promptUpdateInterval =
if (termDimensions._1.isDefined) promptUpdateIntervalMillis
else nonInteractivePromptUpdateIntervalMillis

try Thread.sleep(promptUpdateInterval)
try Thread.sleep(promptUpdateIntervalMillis)
catch {
case e: InterruptedException => /*do nothing*/
}

readTerminalDims(terminfoPath).foreach(termDimensions = _)

synchronized {
if (!runningState.paused && !runningState.stopped) refreshPrompt()
val now = System.currentTimeMillis()
if (
termDimensions._1.nonEmpty ||
(now - lastUpdate > nonInteractivePromptUpdateIntervalMillis)
) {
lastUpdate = now
synchronized {
if (!runningState.paused && !runningState.stopped) refreshPrompt()
}
}
},
}
},
"prompt-logger-updater-thread"
)

Expand Down
5 changes: 1 addition & 4 deletions runner/client/src/mill/runner/client/MillClientMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collections;
import mill.main.client.OutFiles;
import mill.main.client.ServerCouldNotBeStarted;
import mill.main.client.ServerLauncher;
import mill.main.client.Util;
import mill.main.client.*;
import mill.main.client.lock.Locks;

/**
Expand Down
25 changes: 16 additions & 9 deletions runner/client/src/mill/runner/client/MillProcessLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ static int launchMillNoServer(String[] args) throws Exception {
boolean interrupted = false;

try {
Process p = configureRunMillProcess(builder, processDir);
MillProcessLauncher.runTermInfoThread(processDir);
Process p = configureRunMillProcess(builder, processDir);
return p.waitFor();

} catch (InterruptedException e) {
Expand Down Expand Up @@ -230,18 +230,25 @@ static void writeTerminalDims(boolean tputExists, Path serverDir) throws Excepti
Files.write(serverDir.resolve(ServerFiles.terminfo), str.getBytes());
}

public static boolean checkTputExists() {
try {
getTerminalDim("cols", false);
getTerminalDim("lines", false);
return true;
} catch (Exception e) {
return false;
}
}

public static void runTermInfoThread(Path serverDir) throws Exception {
Path sandbox = serverDir.resolve(ServerFiles.sandbox);
Files.createDirectories(sandbox);
boolean tputExists = checkTputExists();

writeTerminalDims(tputExists, serverDir);
Thread termInfoPropagatorThread = new Thread(
() -> {
try {
boolean tputExists;
try {
getTerminalDim("cols", false);
getTerminalDim("lines", false);
tputExists = true;
} catch (Exception e) {
tputExists = false;
}
while (true) {
writeTerminalDims(tputExists, serverDir);
Thread.sleep(100);
Expand Down

0 comments on commit 46a199e

Please sign in to comment.