Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't fail if subprocess finished #166

Merged
merged 3 commits into from
Jul 23, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions core/src/main/scala/replpp/Operators.scala
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,23 @@ object Operators {
val chunkSize = 8192
var remaining = bytes.length
var pos = 0
while (remaining > 0) {
val currentWindow = math.min(remaining, chunkSize)
stdin.buffered.write(value, pos, currentWindow)
pos += currentWindow
remaining -= currentWindow
var stopped = false
Using.resource(stdin) { stdin =>
while (remaining > 0 && !stopped) {
val currentWindow = math.min(remaining, chunkSize)
try {
stdin.buffered.write(value, pos, currentWindow)
pos += currentWindow
remaining -= currentWindow
} catch {
case t: Throwable =>
// most likely the user exited the subprocess
stopped = true
}
}
// flush stdin, but ignore errors
try {stdin.flush()} catch { case t: Throwable => /*ignore*/ }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be safe to just drop this line - closing already implies pushing out all unwritten data.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's what I thought too, but unfortunately that's not the case.
check out the two runs above, I only added this line after seeing the red tests, which were caused by non-flushiness

}

stdin.flush()
stdin.close()
}
}
}
Expand Down
Loading