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

Cargo buffers stdout even with TERM=dumb #6641

Closed
RalfJung opened this issue Feb 7, 2019 · 6 comments
Closed

Cargo buffers stdout even with TERM=dumb #6641

RalfJung opened this issue Feb 7, 2019 · 6 comments
Labels
A-console-output Area: Terminal output, colors, progress bar, etc. C-bug Category: bug

Comments

@RalfJung
Copy link
Member

RalfJung commented Feb 7, 2019

Problem

Even with TERM=dumb, cargo buffers stderr stdout, meaning I do not see things printed to stdout without a trailing \n.

For Miri, we use cargo rustc set up RUSTC_WRAPPER such that we can intercept the call that builds a binary, to instead run it with Miri. Unfortunately, if the application prints to stdout, that output is buffered by Cargo. This is a problem in particular when running a test suite, because it means I cannot see which test is taking long when the test suite just stops.

Possible Solution(s)

When Cargo prints no progress bar, it should leave stdout of the running application entirely unmodified, and not introduce any additional line buffering.

Notes

Output of cargo version: cargo 1.34.0-nightly (2458180 2019-01-27)

@RalfJung RalfJung added the C-bug Category: bug label Feb 7, 2019
@RalfJung RalfJung changed the title Cargo buffers stderr even with TERM=dumb Cargo buffers stdout even with TERM=dumb Feb 8, 2019
@RalfJung
Copy link
Member Author

RalfJung commented Feb 8, 2019

This is likely related to cargo capturing JSON from the compiler.

@ehuss
Copy link
Contributor

ehuss commented Feb 8, 2019

It is unrelated to JSON which uses a separate code path (only if --message-format=json is used). It is buffered so that when multiple compilers are running at the same time that their output doesn't interleave with one another. It's not a perfect solution, but it's a tricky problem (rustc on Windows uses a global lock to accomplish this).

I'm not sure I understand the issue. Is miri sending information without a trailing \n?

@RalfJung
Copy link
Member Author

RalfJung commented Feb 8, 2019

Miri runs an arbitrary program, and that program sends information without a trailing \n. Specifically, it is running the libtest harness (without concurrency), which uses that to show the name of the currently running test -- very useful when working with Miri and a test takes 5min and I want to know which test is slow.

@ehuss ehuss added the A-console-output Area: Terminal output, colors, progress bar, etc. label Sep 23, 2019
@Ark-kun
Copy link

Ark-kun commented Jul 31, 2022

Python has an "unbuffered" option - python -u. Perhaps cargo can do this as well.

https://docs.python.org/3/using/cmdline.html#cmdoption-u

@RalfJung
Copy link
Member Author

FWIW Miri these days uses target.runner to control what happens when the executable is run, so we no longer have this problem.

@epage
Copy link
Contributor

epage commented Oct 23, 2023

Without a use case needing this anymore, I'm going to go ahead and close this. If there is a reason for us to re-evaluate this, let us know!

@epage epage closed this as not planned Won't fix, can't repro, duplicate, stale Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-console-output Area: Terminal output, colors, progress bar, etc. C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

4 participants