Skip to content

Processes with small and infrequent output doesn't get emitted in a timely manner when using sequence to capture the output #39

Open
@rdingman

Description

@rdingman

Describe the bug
I have a process I want to monitor that is long running. It has small and infrequent output that I need to get in as soon as it is available. I'm running this process with swift-subprocess and monitoring its output by using SequenceOutput. In the custom execution closure, I only get the output either when the process exits or when the output size reaches readBufferSize defined in AsyncBufferSequence.

To Reproduce

Here is some sample code that demonstrates the problem:

let script = """
echo "[NOTICE] Important log line"
sleep 3600
"""

let catResult = try await Subprocess.run(
    .path("/bin/bash"),
    arguments: ["-c", script],
    output: .sequence,
    error: .discarded,
    body: { (execution, _) in
        for try await chunk in execution.standardOutput {
            let string = chunk.withUnsafeBytes { String(decoding: $0, as: UTF8.self) }

            if string.hasPrefix("[NOTICE]") {
                // Do Something interesting
                print(string)
            }
        }

        return ""
    }
)

Expected behavior

There should be a mechanism for getting the output as soon as it is available.

Environment (please complete the following information):

  • macOS 15
  • swift-driver version: 1.120.5 Apple Swift version 6.1 (swiftlang-6.1.0.110.21 clang-1700.0.13.3)

Additional context

I'll follow up with a PR that has the sketch for a proposed solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    blockerShow stopping issues for 0.0.1bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions